无法在 MySQLi 中通过引用传递参数
我试图将一个字符串传递到我的 MySQLi 准备好的语句中,但它给了我错误:
I am trying to pass a string into my MySQLi prepared statement but it gives me the error:
在 MySQLi 中不能通过引用传递参数
Cannot pass parameter by reference in MySQLi
相关代码如下:
$kv = json_encode(array($key => $value));
$stmt->prepare("insert into rules (application_id, ruletype, rule_name, rule_info) values (?, ?, ?, ?);");
$stmt->bind_param('iiss', $application_id, 1, $config_name, $kv);
推荐答案
'1' 不能通过引用传递,因为它不是变量而是文字.您需要使用提到的值创建一个变量并绑定它,因为 bind_param()
函数需要通过引用传递的变量.
'1' cannot be passed by reference because it's not a variable but a literal. You need to create a variable with mentioned value and bind it instead because bind_param()
function expects variables passed by reference.
相关文章