問題描述
我正在通過 mysqli::multi_query
運行多個刪除操作,但它搞亂了下一個查詢.正在拋出以下錯誤.
I am running multiple deletes through mysqli::multi_query
and it is messing up the next query in line. The following error is being thrown.
Error - SQLSTATE HY000.
Sql error: Commands out of sync; you can't run this command now
我是否需要以某種方式清除多查詢,以免干擾我的下一個查詢?這個錯誤的原因是什么?
Do I need to somehow clear the multi query so it doesn't mess with my next query? What is the cause of this error?
這就是我運行多查詢的方式:
And this is how I am running my multi query:
function deleteSomeTables($args) {
$sql = 'delete 1;delete another;';
if ($database->multi_query($sql)) {
return true;
} else {
return false;
}
}
我在 Windows 7 上使用最新版本的 Xampp
I am using a recent version of Xampp on windows 7
推薦答案
這幫助我消除了命令不同步"錯誤:
This helped me to remove 'Commands out of sync' error:
do {
$mysqli_conn_obj->use_result();
}while( $mysqli_conn_obj->more_results() && $mysqli_conn_obj->next_result() );
在調用 multi_query 后添加這段代碼,它將使用結果集并解決錯誤.
Add this code just after calling multi_query, it will use the result sets and resolve the error.
這篇關于"命令不同步;你現在不能運行這個命令"- 由 mysqli::multi_query 引起的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!