commands out of sync error[solved]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

commands out of sync error[solved]

Post by raghavan20 »

due to company policies, i could not post code but i will try to explain as much as possible

Code: Select all

$query = '

select query;
select query;
update query;
update query;

'
$conn->multi_query( $query );
$error = $conn->error;

if( $error == "" ){
  $query = 'another update query'
  $conn->query( $query );
}
an exact version of the code that is currently running is what i have presented above, i get this following error.

Code: Select all

Commands out of sync; you can't run this command now
in my code, i am not using the results from the select commands because basically those commands store values into @database_variables which are used later in the update queries.

EDIT: the queries are working fine when they are run using mysql clients/tools but does not run from PHP especially the last update command does not get executed while others are I guess

what do you think is the problem and how can I solve it? Any idea is appreciated.
Last edited by raghavan20 on Wed Nov 01, 2006 10:48 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Have you searched for google with that error message?? I got tons of hits, and explanations of the problem.
Commands out of sync Error in Client

If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order!

This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without a mysql_use_result() or mysql_store_result() in between.
From http://mysqld.active-venture.com/Comman ... _sync.html
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

things seem to work after adding this bit before the last update statement

Code: Select all

// execute multi query; this is very important for the next update statement to be executed
		do {
			/* store first result set */
			if ($result = $conn->store_result()) {

				$result->close();
			}
			/* print divider */
			if ($conn->more_results()) {
				
			}
		} while ($conn->next_result());
Post Reply