Hi fellows,
I have problem in php code and I had searched in days but I didn't found something good.
The problem is when execute the following code and error occured:

$sql = "CALL categoriesSelectByParent($CategId)";
if(!($result = $con->query($sql)))
    echo "Failed: (" . $con->errno . ") " . $con->error;
else {
//Do something with the result.
}

$result->free();

$sql = "CALL booksSelectByCategoryId($CategId)";
if(!($result = $con->query($sql)))
    echo "Failed: (" . $con->errno . ") " . $con->error;
else {
//Do something with the result.
}

the error is:

"Failed: (2014) Commands out of sync; you can't run this command now"

I know the error because of the second call. But how can I solve this.

I hope somebody have the solution.

Recommended Answers

All 6 Replies

try adding under line 8:

$sql->free();

Because you are not flushing the content

or use

unset($sql);

Squidge, the problem still.

Perhaps this thread can help.

pritaeas, none of those solution in this thread help.

It's hard to guess, you don't even mention if you are using MySQLi, or something else.

I had solved by these two lines:

        mysqli_free_result($result);

        mysqli_next_result($con);

I replace it with $result->free();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.