1

In one of my script i use one mysqli_multi_query for some delete operation and then one mysqli_multi_query() for some insert operation. But i am getting following error. "Commands out of sync; you can't run this command now". How can i solve it. Here is my code snippet.

$resourceDeleteSql = "";
$resourceDeleteSql .= "Delete from acl_mr where group_id = $group_id ;";
$resourceDeleteSql .= "Delete from acl_mpr where group_id = $group_id ;";
$resourceDeleteSql .= "Delete from acl_mpfr where group_id = $group_id ;";
$resourceDeleteSqlResult = mysqli_multi_query($con, $resourceDeleteSql) or die(mysqli_error($con));  
if ($resourceDeleteSqlResult) {

    $resourceInsertSql = '';
    foreach ($resource as $moduleKey => $module) {

        if (is_array($module)) {
            foreach ($module as $pageKey => $page) {
                if (is_array($page)) {

                    foreach ($page as $field) {
                        $resourceInsertSql .= "INSERT INTO acl_mpfr (group_id ,field_sys_name ,page_sys_name,module_sys_name) VALUES ( '$group_id', '$field', '$pageKey', '$moduleKey');";
                    }
                } else {

                    $resourceInsertSql .= "INSERT INTO acl_mpr (`group_id` ,`page_sys_name`,`module_sys_name`) VALUES ( '$group_id','$page', '$moduleKey');";
                }
            }
        } else {
            $resourceInsertSql .= "INSERT INTO acl_mr (`group_id` ,`module_sys_name`) VALUES ( '$group_id', '$module');";
        }
    }

    $resourceInsertSqlResult = mysqli_multi_query($con, $resourceInsertSql) or die(mysqli_error($con));
karim_fci
  • 1,212
  • 2
  • 17
  • 36

1 Answers1

1

check this link : http://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html

If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order.

This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.

Shiva Saurabh
  • 1,281
  • 2
  • 25
  • 47
Ananth
  • 1,520
  • 3
  • 15
  • 28