dtc9222 2013-05-27 16:35
浏览 33
已采纳

codeigniter mysqli驱动程序破坏了会话类

So I have been using mysql driver with codeigniter , but now I need to execute stored procedures and for that Mysqli driver is needed . Because apparently mysql driver doesn't support Stored Procedures. Now I can execute Stored Procedures But the native session manager is broken . It can't store session in Ci_session table . gives the following error

Error Number: 2014

Commands out of sync; you can't run this command now

UPDATE ci_sessions SET last_activity = 1369672449, user_data = 'a:2:{s:9:\"user_data\";s:0:\"\";s:7:\"user_id\";s:1:\"1\";}' WHERE session_id = '1b29074ae286b900b02e410916d93f26'

Filename: F:\xampp\htdocs\project\system\database\DB_driver.php

Line Number: 330

Help!

  • 写回答

1条回答 默认 最新

  • dongzao9044 2013-05-27 19:37
    关注

    This is a known/common problem with the mysqli driver in Code Igniter. You can overcome it by replacing the _execute method in mysqli_driver.php with the below:

    public function _execute($sql)
    {
        // Free result from previous query
        @mysqli_free_result($this->result_id);
    
        $sql = $this->_prep_query($sql);
    
        // get a result code of query (), can be used for test is the query ok
        $retval = @mysqli_multi_query($this->conn_id, $sql); 
    
        // get a first resultset
        $firstResult = @mysqli_store_result($this->conn_id);
    
        // free other resultsets
        while (@mysqli_next_result($this->conn_id)) {
            $result = @mysqli_store_result($this->conn_id);
            @mysqli_free_result($result);
        }
    
        // test is the error occur or not 
        if (!$firstResult && !@mysqli_errno($this->conn_id)) {
            return true;
        }
    
        return $firstResult; 
    }
    

    Not wanting to change the system files I've taken this a step further and followed the instructions here: https://github.com/EllisLab/CodeIgniter/wiki/Extending-Database-Drivers to create my own MY_DB_mysqli_driver in the application/libraries folder and then placed the new _execute method into that to override the original in the parent class.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用