Cannot pass parameter 2 by reference error in php PDO(无法通过 php PDO 中的引用错误传递参数 2)
问题描述
我收到错误:无法通过引用传递参数 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法通过 php PDO 中的引用错误传递参数 2


- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01