美文网首页PHP经验分享
CI框架中调用存储过程后在执行其他语句碰到的问题

CI框架中调用存储过程后在执行其他语句碰到的问题

作者: 西瓜很甜哟 | 来源:发表于2018-09-20 14:45 被阅读3次

    项目开发中碰到的问题,数据库写了个存储过程,在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();
    
    

    相关文章

      网友评论

        本文标题:CI框架中调用存储过程后在执行其他语句碰到的问题

        本文链接:https://www.haomeiwen.com/subject/xxqnnftx.html