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 calling
mysql_use_result()
or
mysql_store_result()
in
between.
User Comments
I have just identified and resolved a recurring problem with this error when using PHP in FreeBSD 5.3.
If you're using mysql_pconnect and you call that function repeatedly, and then execute queries on that connection, you will receive this error message. This may be due to the way persistent connections are handled in FreeBSD.
The workaround is to use mysql_connect, which does not generate this error message.
It's best to avoid using mysql_pconnect() in any case, as persistent connections are not supported in PHP 5's mysqli extension (to which all PHP/MySQL development will eventually need to be ported), and really aren't of benefit to Web applications.
This error just occured coding C using the "mysqlclient include" having multiple instances of the structure:
struct DB {
MYSQL mysql;
MYSQL_RES *result;
MYSQL_FIELD *field;
MYSQL_ROW row;
unsigned long numRows;
unsigned long numFields;
};
... and THEN forgetting to call init/connect/select_db on all but one.
Just wasted half an hour :| Hope it's going to be of use for the next person.
Regards, Peter Sierst Nielsen
The problem is avoided if prepared statements with cursors are used:
const unsigned long type = (unsigned long) CURSOR_TYPE_READ_ONLY;
mysql_stmt_attr_set (stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
Add your own comment.