【发布时间】:2010-12-09 00:16:00
【问题描述】:
在 PDO 中使用准备好的语句时,我应该为每个 db 调用“构建”一个准备好的语句,还是可以为所有调用使用一个语句? 示例:
class DB{
...
function query($sqlStatementString,$data){
$this->sth->prepare($sqlStatementString);
$this->sth->execute($data);
}
...
}
或
class User{
...
function doSomething(){
$sthForDoSomething->prepare(...);
$sthForDoSomething->execute(...);
}
...
function jump(){
$sthForJump->prepare(...);
$sthForJump->execute(...);
}
}
使用其中一种方法对内存/速度有影响吗? 谢谢!
【问题讨论】:
-
要将您的代码显示为代码块,您需要将它们缩进四个空格(突出显示它们并按 Ctrl+K)。
标签: php pdo prepared-statement