mysqli的bind_param()预计为基准,给出的价值 [英] mysqli bind_param() expected to be a reference, value given
问题描述
想不通,什么导致错误的参数3 mysqli_stmt :: bind_param()预计为参考,值...给出
Can't figure out, whats causing error Parameter 3 to mysqli_stmt::bind_param() expected to be a reference, value given in...
PDO
$query = "INSERT INTO test (id,row1,row2,row3) VALUES (?,?,?,?)";
$params = array(1,"2","3","4");
$param_type = "isss";
$sql_stmt = mysqli_prepare ($mysqli, $query);
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($sql_stmt, $param_type), $params));
mysqli_stmt_execute($sql_stmt);
也试过OOP
OOP
$insert_stmt = $mysqli->prepare($query);
array_unshift($params, $param_type);
call_user_func_array(array($insert_stmt, 'bind_param'), $params);
$insert_stmt->execute();
但同样的错误,只是现在参数2引起的问题。
But same error, only that now Parameter 2 is causing problem.
那么,什么是错$ PARAMS?我需要$ PARAMS是值的数组。
So, what's wrong with $params? I need $params to be an array of values.
推荐答案
从PHP实况:
护理必须与call_user_func_array结合使用mysqli_stmt_bind_param()时,应考虑()。需要注意的是mysqli_stmt_bind_param()需要的参数按引用传递,而call_user_func_array()可以作为参数接受,可以重新present引用或值的变量列表。
Care must be taken when using mysqli_stmt_bind_param() in conjunction with call_user_func_array(). Note that mysqli_stmt_bind_param() requires parameters to be passed by reference, whereas call_user_func_array() can accept as a parameter a list of variables that can represent references or values.
在页面上的mysqli-stmt.bind-参数你有不同的解决方案
And on the page mysqli-stmt.bind-param you have different solutions:
例如:
call_user_func_array(array($stmt, 'bind_param'), refValues($params));
function refValues($arr){
if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
{
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
return $arr;
}
这篇关于mysqli的bind_param()预计为基准,给出的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!