2016-01-21 114 views
0

我想获得一个列dateTime的值,然后使用这些值得到当天作出的条目数。所以我传递一个数组给bind_param。但在这里我得到的错误:bind_param给出错误“参数3到mysqli_stmt_bind_param()有望成为一个参考”

"Parameter 3 to mysqli_stmt_bind_param() expected to be a reference"

我也试过了似乎不工作的评论方法。这里是代码:

<?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

[mysqli的绑定\ _Param()预期为基准,给定值(的可能的复制http://stackoverflow.com/questions/16120822/mysqli -bind-param-expected-to-be-a-reference-value-given) –

回答

0

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

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

请阅读mysqli_stmt_bind_param函数参照here

+0

$ result是准备好的语句字符串 – Saeesh

相关问题