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!
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.