問題描述
我收到錯誤:無法通過引用傳遞參數 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 語句,作為 docs 對于 bindparam 說
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!