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

前端 未结 4 1082
一生所求
一生所求 2021-01-06 11:38

I am using MySQL with PHP, Codeigniter. I had a question which was answered by bluefeet in the post here

I created a stored procedure for the second solution by blue

4条回答
  •  失恋的感觉
    2021-01-06 12:10

    Got the Answer! It seems like codeigniter's mysql driver has bugs handling stored procedures.

    I changed the drivers from mysql to mysqli in the config/database file by changing

    $db['default']['dbdriver'] = 'mysql';
    

    to

    $db['default']['dbdriver'] = 'mysqli';
    

    Post that i modified the system/database/drivers/mysqli/mysqli_result.php file and added the below function

    function next_result()
    {
      if (is_object($this->conn_id))
      {
          return mysqli_next_result($this->conn_id);
      }
    }
    

    and modified the model as below

    $db = $this->load->database('mailbox',TRUE);
    $qry_res = $db->query('Call circle_pending_p()');
    
    echo $db->_error_message();
    $res = $qry_res->result_array();
    
    $qry_res->next_result();
    $qry_res->free_result();
    
    if (count($res) > 0) {
          return $res;
    } else {
          return 0;
    }
    

    This solved the problem!

提交回复
热议问题