这是我的代码如下:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。