問(wèn)題描述
我正在通過(guò) mysqli::multi_query
運(yùn)行多個(gè)刪除操作,但它搞亂了下一個(gè)查詢.正在拋出以下錯(cuò)誤.
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
我是否需要以某種方式清除多查詢,以免干擾我的下一個(gè)查詢?這個(gè)錯(cuò)誤的原因是什么?
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?
這就是我運(yùn)行多查詢的方式:
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
推薦答案
這幫助我消除了命令不同步"錯(cuò)誤:
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() );
在調(diào)用 multi_query 后添加這段代碼,它將使用結(jié)果集并解決錯(cuò)誤.
Add this code just after calling multi_query, it will use the result sets and resolve the error.
這篇關(guān)于"命令不同步;你現(xiàn)在不能運(yùn)行這個(gè)命令"- 由 mysqli::multi_query 引起的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!