I am trying to use asynchronous queries via PHP MySQLi.
The following code has been simplified, the original is code is too verbose to list here because of class dependencies and all that. Also please assume the reference to the connection mysqli_handle
has already been setup.
$query_1 = "SHOW TABLES FROM moxedo";
$query_2 = "CREATE TABLE `moxedo`.`mox_config_n85ad3` (`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT , `group_id` INT(3) UNSIGNED NOT NULL , `is_enabled` INT(1) UNSIGNED NOT NULL , `tag` VARCHAR(255) NOT NULL , `name` VARCHAR(80) NOT NULL , `value` VARCHAR(255) NOT NULL , `description` TEXT NOT NULL , `init_params` TEXT NOT NULL , `datetime_added` DATETIME NOT NULL , `datetime_lastmodified` DATETIME NOT NULL , `timestamp_univ` BIGINT(14) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = INNODB
";
$query_3 = "ALTER TABLE `moxedo`.`mox_config_n85ad3` ADD UNIQUE `ix_u_tag_oq` ( `tag` )";
$query_4 = "SHOW TABLES FROM moxedo";
if (!$mysqli_stmt_obj = $mysqli_handle->query($query_1))
{
printf("Error: %s\n", $mysqli_handle->error);
}
if (!$mysqli_stmt_obj = $mysqli_handle->query($query_2, MYSQLI_ASYNC))
{
printf("Error: %s\n", $mysqli_handle->error);
}
if (!$mysqli_stmt_obj = $mysqli_handle->query($query_3, MYSQLI_ASYNC))
{
printf("Error: %s\n", $mysqli_handle->error);
}
if (!$mysqli_stmt_obj = $mysqli_handle->query($query_4))
{
printf("Error: %s\n", $mysqli_handle->error);
}
The call to Query 1 goes through OK. The call to Query 2 also goes through OK.
However, I'm getting "Commands out of sync; you can't run this command now" errors when I try to execute Query 3 and Query 4. From my research online I found some information on using mysqli_free_result
but Query 2 and Query 3 return no resultset.
What do I need to do to properly finalize the asynchronous call so that I can make multiple calls without getting this error?