phpmysqlmysqlimulti-query

MySqli Error 2014 on new connection


when running the following code I encounter the error 2014:"Commands out of sync; you can't run this command now"

$newConnection  = new mysqli("127.0.0.1", username, password, "", 3306);
$nativeQueryResult  = $newConnection->multi_query ("SELECT 1;");

But I do not get the same error when using a regular query instead of a multi query e.g.

$nativeQueryResult  = $newConnection->query ("SELECT 1;");

My understanding of this error is that it occurs when the results of a previous query on the same connection have not been freed, but as this is a new connection I do not think that this would still apply?

EDIT: Please note that I am not performing multiple calls to multi_query, this is not a duplicate of other common problems with this behaviour. This is the first query of a new connection.

EDIT: Software Versions: OSX 10.10.2, PHP 5.5.19, MySql 5.6.22


Solution

  • Discovered the problem, simply put: there is no problem...

    The the error message I was reporting came from inspecting the mysqli connection's variables whilst the script was paused at a breakpoint directly after the query is executed.

    However if I echo out these variables (e.g. 'error', 'errno') they do NOT contain the values that my IDE claimed they did.

    After cycling through all the results of the query and freeing the mysqli_results objects the error that can be viewed through the IDE disappears, this makes me believe that this is a problem with how the IDE grabs these variables and it is displaying a false error.

    Following this discovery I ran my query directly through a mysql client and found that there was a different syntax error in it that was causing that actual problem, the 2014 error was just masking the actual issue.

    Thanks to everyone for their help, I am using Netbeans 8.0.2 (Build 201411181905) and if anyone knows if this behaviour is the same in other IDEs I'd love to hear about it.