2010-09-22 110 views
0

我正在嘗試做一些調用,但第二個查詢失敗,並且命令'Commands out of sync;你現在不能運行這個命令'錯誤。當使用mysqli和預處理語句時,命令不同步

的代碼看起來是這樣的:

$sql="call listReport();"; 
$results = mysqli_query($link,$sql); 
$arr=array(); 
while($row=mysqli_fetch_array($results)) { 
    array_push($arr,$row); 
} 
mysqli_free_result($results); 

// then I have this 

// but this fails, giving the above mentioned error 
$stmt = @mysqli_prepare($link,"select ........") or die(mysqli_error($link)); 
@mysqli_stmt_bind_param($stmt, 's', $s); 
@mysqli_stmt_execute($stmt); 
@mysqli_stmt_bind_result($stmt, $s); 
@mysqli_stmt_fetch($stmt); 
@mysqli_stmt_close($stmt); 

我實際使用mysqli_free_result($results);但沒有奏效。我錯過了什麼?

+0

您可以使用此代碼重現錯誤?您正在推送'$ row'來定義'$ arr',並且不使用'$ arrows'。不要用'@'來壓制錯誤,任何錯誤信息都會有幫助。 (可能是一個有用的鏈接:[在MySQL網站上解釋此錯誤](http://dev.mysql.com/doc/refman/5.1/en/commands-out-of-sync.html)。) – Lekensteyn 2010-09-22 13:59:48

+0

On the第二組的第一個方法失敗,die節點打印錯誤。 – Pentium10 2010-09-22 14:02:56

回答

1

的問題是,MySQL的存儲過程可以返回不同的結果集,所以你應該使用mysqli_multiquery

"PHP 5 and MySQL 5 Stored Procedures Error"

+0

該過程只有一個選擇。 – Pentium10 2010-09-22 14:15:11

+0

這不是關於在你的過程中只有一個選擇,如果你閱讀MySQL文檔,你會看到「要編寫使用CALL SQL語句執行存儲過程來生成結果集的C程序,必須啓用CLIENT_MULTI_RESULTS標誌。」 – armonge 2010-09-22 14:30:13

+0

http://dev.mysql.com/doc/refman/5.0/en/call.html – armonge 2010-09-22 14:30:40