bind_param给出错误"参数3到mysqli_stmt_bind_param()期望作为参考"

时间:2016-01-21 07:16:06

标签: php mysqli bindparam

我试图获取列dateTime的值,然后使用这些值获取当天的条目数。所以我将一个数组传递给bind_param。但在这里我得到了错误:

  

"参数3到mysqli_stmt_bind_param()应该是参考"

我也尝试过评论的方法,它似乎也没有用。这是代码:

<?php
$hostname = "localhost";
$database = "ti_project";
$username = "root";
$password = "";
$mysqli = new mysqli($hostname, $username, $password, $database);

$query = "SELECT dateTime FROM feedback";
$result = $mysqli->prepare($query);
/*$result->bind_param('s', $datetime);*/
$result->execute();

$result->bind_result($Date);

while ($result->fetch()){
 $feedbackdate[] = array($Date);
}

$type="s";
$query = "SELECT COUNT(*) FROM feedback WHERE dateTime = ?";
$result = $mysqli->prepare($query);
call_user_func_array('mysqli_stmt_bind_param', 
                array_merge (array($result, $type),$feedbackdate));

$result->execute();


/*$ref    = new ReflectionClass('mysqli_stmt'); 
$method = $ref->getMethod("bind_param"); 
$method->invokeArgs($result,$feedbackdate); 
$result->execute(); 
*$result->bind_*result($count);*/

while ($result->fetch()){
    $Count[] = array(
    'Count' => $count
);
}
echo json_encode($Count);

$result->close();

$mysqli->close();

?>

1 个答案:

答案 0 :(得分:0)

在函数调用中缺少语句变量。此函数接受3个参数而不是2.缺少提供准备好的语句。

call_user_func_array('mysqli_stmt_bind_param', $stmt, array_merge (array($result, $type), $feedbackdate));

请阅读mysqli_stmt_bind_param函数参考here