"命令不同步;您不能立即运行此命令" -由mysqli :: multi_query引起 [英] "Commands out of sync; you can't run this command now" - Caused by mysqli::multi_query

查看:88
本文介绍了"命令不同步;您不能立即运行此命令" -由mysqli :: multi_query引起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过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引起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆