CI框架中调用存储过程报错:Commands out of sync; you can't run this command now

3 篇文章 0 订阅
1 篇文章 0 订阅

项目开发中碰到的问题,数据库写了个存储过程,在ci框架中调用此存储过程,碰到了问题,接触ci框架时间不长,摸索了好半天,才终于解决。
问题如下:

$common = $this->db->query("call welcome_common_data($role_id)")->row_array();

执行之后,再去执行其他查询语句,报错如下:

Error Number: 2014 Commands out of sync; you can’t run this command now

查了一下是调用存储过程之后,要释放资源,关闭连接即:

$this->db->close();

如果只加上面那一行的话,又会碰到下面的问题:
Call to a member function real_escape_string() on boolean

$this->db->close() 源码如下:

/**
 * Close DB Connection
 *
 * @return void
 */
public function close()
{
   if ($this->conn_id)
   {
      $this->_close();
      $this->conn_id = FALSE;
   }
}

所以确实要重置db,添加下面代码即可解决:

$this->db->close();
$this->db->initialize();

$this->db->reconnect();

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值