[英]PHP: «Commands out of sync» if I mysqli::query() again after a call to a results-giving stored procedure
我的數據庫中有一個存儲過程,它返回表中的所有記錄:
CREATE PROCEDURE showAll()
BEGIN
SELECT * FROM myTable;
END
SP的工作方式與預期一致。 但是,如果我在php腳本中調用它,然后我嘗試再次查詢數據庫,它總是失敗:
// $mysqli is a db connection
// first query:
if (!$t = $mysqli->query("call showAll()"))
die('Error in the 1st query');
while ($r = $t->fetch_row()) {
echo $r[0] . "<br>"; // this is ok
}
$t->free(); // EDIT (this doesn't help anyway)
// second query (does the same thing):
if (!$t = $mysqli->query("SELECT * from myTable"))
die('Error in the 2nd query'); // I always get this error
while ($r = $t->fetch_row()) {
echo $r[0] . "<br>";
}
值得注意的是,如果我交換了兩個查詢(即我最后調用了存儲過程),它的工作沒有任何錯誤。 要在第二個查詢之前關閉()結果沒有幫助。 一些提示?
編輯:mysqli :: error()是:«命令不同步; 你現在不能運行這個命令»。
關於mysqli.query的php.net / manual條目的評論已經更新,現在包括一個答案。 總而言之,在$ t-> close()之后調用$ mysqli-> next_result()。 感謝petrus.jvr!
@jymian,你的答案不明確。 請清楚表達。
使用$t->free()
釋放結果集后,
調用$mysqli->next_result()
。
以上調用將為下一個結果集做准備,您不會出現同步錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.