CodeIgniter Forums
Commands out of sync; you can't run this command now (with free_result()) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Commands out of sync; you can't run this command now (with free_result()) (/showthread.php?tid=64288)



Commands out of sync; you can't run this command now (with free_result()) - cupboy - 02-03-2016

Here is the code:
   $sql = "call getCase('$myTable', '$casenum', '$fname','$lname')";    
   $q = $this->db->query($sql);    
   $data['hrg'] = $q->result(); // $hrgs
   $q->free_result(); // http://www.codeigniter.com/user_guide/database/results.html

When I execute the next query I get the commands out of sync error.
It looks to me like it is coded correctly. Any ideas of the problem?


RE: Commands out of sync; you can't run this command now (with free_result()) - skunkbad - 02-03-2016

See this on my website:

http://community-auth.com/blog-posts/commands-out-of-sync-error-when-using-stored-procedures


PHP Code:
$sql "call getCase( '$myTable', '$casenum', '$fname', '$lname')";    
$q 
$this->db->query($sql);    
$data
['hrg'] = $q->result();
/**
 * Free result is not good enough, because procedures 
 * will often return more than one result. The solution
 * is to use mysqli_next_result(). If you're not using
 * mysqli, then you're going to need to figure out how 
 * to get the next result using some other way.
 */
mysqli_next_result$this->db->conn_id ); 



RE: Commands out of sync; you can't run this command now (with free_result()) - Anonymos - 08-27-2016

My solution.

\system\database\DB_result.php 

....
public function result_array()
{
              .....
              is_null($this->row_data) OR $this->data_seek(0);
              if($this->conn_id->affected_rows > 0) {// My custom
                    while ($row = $this->_fetch_assoc())
                    {
                            $this->result_array[] = $row;
                    }
                    $this->free_result(); // My custom
                    @mysqli_next_result($this->conn_id); // My custom
              }

              return $this->result_array;
}


RE: Commands out of sync; you can't run this command now (with free_result()) - InsiteFX - 08-27-2016

You should never edit and write to a CodeIgniter system file NEVER!


RE: Commands out of sync; you can't run this command now (with free_result()) - ozzy mandiaz - 08-29-2016

(08-27-2016, 10:32 AM)InsiteFX Wrote: You should never edit and write to a CodeIgniter system file NEVER!

so it would be best practice then to extend and/or override the method in DB_Driver, then?

--- OM


RE: Commands out of sync; you can't run this command now (with free_result()) - InsiteFX - 08-29-2016

Correct, the CodeIgniter system folder should never be touched because of updating it by coping the the new system folder over the old one.


RE: Commands out of sync; you can't run this command now (with free_result()) - skunkbad - 08-29-2016

(08-29-2016, 09:22 AM)ozzy mandiaz Wrote:
(08-27-2016, 10:32 AM)InsiteFX Wrote: You should never edit and write to a CodeIgniter system file NEVER!

so it would be best practice then to extend and/or override the method in DB_Driver, then?

--- OM

Good luck with that. Unless something changed, extending the database classes has never been easy.