2016-01-21 112 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

相關問題