数据库
首页 > 数据库> > php – 命令不同步;你现在无法使用mysql存储过程在SugarCRM中运行此命令

php – 命令不同步;你现在无法使用mysql存储过程在SugarCRM中运行此命令

作者:互联网

这是我的代码如下:

public function listParkedAccounts($days = NULL)
{
    global $db;
    $days_db = (empty($days))?"7":$days;
    $stmt    = "CALL parked_accounts('.$days_db.')";

    $result       = $db->query($stmt,true,'Failed to fetch aged author record');
    $aged_authors = mysqli_fetch_all($result,MYSQLI_ASSOC);
    //mysql_free_result($result); tried this

    $counter = 0;
    $data    = null;

    foreach($aged_authors as $authors){
        if(empty($authors['call_descp'])){
            $stmt_notes   = "SELECT description FROM notes WHERE description IS NOT NULL AND parent_id = '".$authors['call_id']."' AND parent_type = 'Calls' ORDER BY date_entered DESC LIMIT 1";
            $notes_descp = $db->getOne($stmt_notes, TRUE, 'Error retrieving call notes');


            $notes = (!empty($notes_descp))?$notes_descp[0]['description']:"No Notes";

        }else{
           $notes = (!empty($authors['call_descp']))?$authors['call_descp']:"No Notes";
        }
        $lead = 'stuff';
        $data[$counter]['lead_id']    = $lead;
        $data[$counter]['call_notes'] = $notes;
        $counter++;
    }

    $size = sizeof($data);
    $json_vals['draw'] = "1";
    $json_vals['recordsTotal'] = $size;
    $json_vals['recordsFiltered'] = $size;
    $json_vals['data'] = ($size > 0)?$data:array();
    return $json_vals;
}

我的问题是这个错误信息:

Error retrieving call notes Query Failed: SELECT description FROM
notes WHERE description IS NOT NULL AND parent_id =
‘123’ AND parent_type = ‘Calls’ ORDER
BY date_entered DESC LIMIT 1: MySQL error 2014: Commands out of sync;
you can’t run this command now

我从阅读this中了解到,我需要释放结果或存储它们但是当我尝试这些时我仍然得到相同的错误信息.虽然我不太确定我应该在哪里释放结果,或者我是否正确地执行它们.这是我第一次使用存储过程.

解决方法:

调用存储过程时,存储过程可能包含需要处理的多个结果集.如果您只处理第一个结果集并继续尝试使用相同的连接执行另一个查询,那么您将获得

“Commands out of sync”

错误.

要解决这个问题,不要使用$db->查询mysqli_fetch_all(顺便说一下,不要混合面向对象的样式和程序样式),你应该使用multi_query.

PHP文档中显示了如何使用行处理多个结果集的示例:
http://php.net/manual/en/mysqli.multi-query.php

标签:php,mysql,sugarcrm,suitecrm
来源: https://codeday.me/bug/20190705/1390221.html