1
這是插入行的簡單代碼。 它運行良好的PHP 5.6,但通過PHP 7.0.9我得到的錯誤:「參數3 mysqli_stmt_bind_param()預計是一個參考」。參數3到mysqli_stmt_bind_param()有望成爲一個參考:php5.6 vs php7
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;
}
...
$sql = "INSERT INTO table (player_id,ctime) VALUES(?,?)";
$types = "ii";
$args = array(10, time());
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name, $db_port, $db_sock);
if(!$conn)
throw new Exception("Could not connect to mysql server");
$stmt = mysqli_prepare($conn, $sql);
if(!$stmt)
throw new Exception("Could not prepare sql");
$res = call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $types), refValues($args)));
if(!$res)
throw new Exception("Could not bind params");
if(!mysqli_stmt_execute($stmt))
throw new Exception("Could not execute stmt");
它是什麼錯誤?
它需要一個參考,所以你不能使用array_merge的返回值,你需要爲它爲參數引用3+實際變量。 – Devon
從我的測試中,您有refValues函數應該照顧參考。它在7.0.5上適用於我。 – Devon
@Devon,謝謝! – ivhome