无法通过PHP PDO中的参考错误传递参数2 [英] Cannot pass parameter 2 by reference error in php PDO
问题描述
我遇到了错误: 无法通过引用将参数2传入.....
I am getting the error: Cannot pass parameter 2 by reference in.....
在此行...
$stmt1->bindParam(':value', $_SESSION['quantity'.$i] * $_SESSION['price'.$i], PDO::PARAM_STR);
上面的代码有什么问题?
What is wrong with code above ??
推荐答案
它期望第二个参数是可以通过引用传递的变量.假设$stmt1
是PDO语句,则如bindparam的 docs 所说的
It expects the second paramter to be a variable which can be passed by reference. Assuming $stmt1
is a PDO statement then, as the docs for bindparam say
与PDOStatement :: bindValue()不同,该变量被绑定为引用 并且只会在PDOStatement :: execute()为 叫.
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.
您的第二个参数是表达式($_SESSION['quantity'.$i] * $_SESSION['price'.$i]
)而不是变量.既然您似乎现在想评估该表达式,我想您应该改用bindValue()
.
Your second param is an expression ($_SESSION['quantity'.$i] * $_SESSION['price'.$i]
) not a variable. Since you appear to want to evaluate the exptression now, I guess you should used bindValue()
instead.
这篇关于无法通过PHP PDO中的参考错误传递参数2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!