gpt4 book ai didi

php - mysqli_stmt_bind_param() 的参数 3 预计是引用 : php5. 6 vs php7

转载 作者:行者123 更新时间:2023-11-28 23:27:42 24 4
gpt4 key购买 nike

这是插入行的简单代码。它在 php 5.6 中运行良好,但在 php 7.0.9 中我得到错误:“参数 3 to mysqli_stmt_bind_param() expected to be a reference”。

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");

有什么问题吗?

最佳答案

答案是将 refValues 函数更改为

function refValues(&$arr)

关于php - mysqli_stmt_bind_param() 的参数 3 预计是引用 : php5. 6 vs php7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38592480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com