下面是我的代码:
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是我需要释放结果或存储它们但是当我尝试那些时我仍然收到相同的错误消息。虽然我不太确定我应该在哪里释放结果,或者我是否正确地做它们。这是我第一次使用存储过程。
最佳答案
当您调用存储过程时,存储过程可能包含多个您需要处理的结果集。如果您只处理第一个结果集并继续尝试使用相同的连接执行另一个查询,您将得到 p>
"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/