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

标签 php mysql sugarcrm suitecrm

下面是我的代码:

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->query + mysqli_fetch_all (顺便说一句,尽量不要混合面向对象的风格和程序风格)你应该使用 multi_query .

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

关于php - 命令不同步;您现在无法使用 mysql 存储过程在 SugarCRM 中运行此命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46541579/

相关文章:

php - PHP 中的 SQL Server 存储过程输出参数

php - 从输入(datetime_local)字段进行MYSQL查询

如果已选择 id,则 MySQL SELECT 递增计数器

php - MySQLi 圆 Rand()

mysql - 用户 'root' @'%' 访问数据库 'information_schema' 被拒绝

php - 在 SugarCRM 中将国家/地区文本字段更改为下拉列表

sugarcrm - 广告系列和产品模板之间的自定义多对多关系子面板

php - 如何获取表的主键?

javascript - 使用 mysql 和 javascript 计算链接的点击次数

field - SugarCRM:编码自定义中间名字段