Jump to content

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


hitech123

Recommended Posts

Hello,

 

We have large queries and we have decided to use a stored procedure of MYSQL. The attached sql.php was made using mysql function of mysql, but for using stored procedure, i just changed all mysql function to mysqli. The code is working fine except that we are getting "Command out of sync." error. We get this error when first query to execute stored procedure follows another query to execute stored procedure or even simple sql query. We have made a research on the error and we understood that this error comes when the resultsets are not freed. But as i go through class we have freed mysqli results wherever necessary. We dont know what is causing the error, We had worked on the project for 6 months so we can't change everything but the sql.php. Any help will be much appreciated.

 

Regards

Анил Шарма

 

[attachment deleted by admin]

Link to comment
Share on other sites

well, i guess you guys love tackling syntax error issues with less than 10 lines php codes only.......if you have looked at the code at least for 30 secs you'd have understood the problem. The problem is with "mysqli_fetch_object". If we go through an object oriented way the error shows in the 2nd query.

Link to comment
Share on other sites

well, i guess you guys love tackling syntax error issues with less than 10 lines php codes only.......if you have looked at the code at least for 30 secs you'd have understood the problem. The problem is with "mysqli_fetch_object". If we go through an object oriented way the error shows in the 2nd query.

 

try changing this portion in you code:

// Store Query Results

$num_rows=0;

while ( $row = @mysqli_fetch_object($this->result) )

{

// Store relults as an objects within main array

$this->last_result[$num_rows] = $row;

$num_rows++;

}

 

@mysqli_free_result($this->result);

 

to this one:

  do {

      while( $row = mysqli_fetch_object($this->result) ){

        $this->last_result[$num_rows] = $row;

        $num_rows++

      }

  }  while (mysqli_next_result($this->dbh));

 

mysqli_free_result() is not the solution... error is due to the fact that any stored procedure potentially return more that one resultset (one being just a execution status), therefore you MUST USE/DUMP all the resultsets before call/execute other SQL sentence, otherwise you will get the indicated error (out of sync)

Link to comment
Share on other sites

Thanks Mikosiko, u r right too.

Actually i solved this issue last night. I added following function in the class.

 

function ClearRecordsets(){
//mysqli_free_result($this->result);
while(mysqli_next_result($this->dbh)){
if($l_result = mysqli_store_result($this->dbh)){
mysqli_free_result($l_result);
}
}
}

 

Now it's working perfect.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.