Commands are not synchronized; you cannot run this command now in SugarCRM using the mysql stored procedure

This is my code below:

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;
}

My problem here is in this error message:

Error receiving comments about calls Request error: SELECT description FROM notes WHERE description NOT NULL AND parent_id = '123' AND parent_type = 'Calls' ORDER BY date_entered DESC LIMIT 1: MySQL 2014 error: commands not synchronized; you cannot run this command now

, this, , , , . , , . , .

+4
2

, , . ,

" "

.

, $db->query + mysqli_fetch_all (btw - ), multi_query.

PHP: http://php.net/manual/en/mysqli.multi-query.php

+1

:

$notes_descpRes = $db->query($stmt_notes);
$notes_descp  = $db->fetchByAssoc($notes_descpRes); 
$notes = (!empty($notes_descp))?$notes_descp['description']:"No Notes";

:

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_descpRes = $db->query($stmt_notes);
            $notes_descp  = $db->fetchByAssoc($notes_descpRes); 

            $notes = (!empty($notes_descp))?$notes_descp['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;
}

.

0

Source: https://habr.com/ru/post/1686798/


All Articles