[英]Using same variable again in PDO queries
I'm using PDO prepared statement. 我正在使用PDO准备的语句。 Here in the code i use variable
res
for first prepare statement & operations. 在此代码中,我将变量
res
用于首先准备语句和操作。
$res=$db->prepare("//code//");
$res->execute($array);
$count=$res->rowCount();
$res=$db->prepare("//code//");
$res->execute($array);
$res->fetch();
Will it create problems if i use reuse the variable for another prepared statement? 如果我将变量用于另一个准备好的语句,是否会产生问题? Is it a wrong practice and should i use another variable for other statement?
这是错误的做法,我是否应该在其他语句中使用另一个变量?
If you're done with that variable, I think you can safely reuse it (I would do it), but some code conventions try to avoid this kind of behaviour. 如果使用完该变量,我认为您可以安全地重用它(我会这样做),但是某些代码约定试图避免这种行为。
See for example this other question: is it acceptable to recycle or reuse variables? 例如,参见另一个问题: 回收或重用变量是否可以接受?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.