You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When making a successful query to getOne() that returns rows, getOne() returns too early and never reaches the free() call. This results in MySQL throwing the error "Commands out of sync, you can't run the command now"
The return statement means that $this->free($res) is never called if the query returned results, it should instead follow the other statements by storing the return value and returning after calling free().
The text was updated successfully, but these errors were encountered:
Although technically you are right, it shouldn't be an issue, as you shouldn't use getOne() with a query that returns more than 1 row.
Adding LIMIT 1 to your query should solve the problem.
Besides, I cannot reproduce this error. mysqli_query is buffered by default, which means that it's impossible to get "Commands out of sync, you can't run the command now" error. Can you please provide a code that can help me to reproduce this error?
Code along the lines of the following caused it for me:
$objType = $mySql->getOne(
'CALL GetObjectTypeById(?i);',
$objId
);
// Error occurs on this call to getRow
$objDetails = $mySql->getRow(
'CALL GetObjectDetails(?i);',
$objId
);
GetObjectTypeById is just a procedure that does a single SELECT statement and returns a single value, in my case it just returned 5 .
The procedure looks roughly like:
CREATE PROCEDURE GetObjectTypeById (IN queryId BIGINT UNSIGNED)
BEGIN
SELECT ObjType
FROM MyObjects
WHERE Id = queryId;
END
The second call to GetObjectDetails is what then causes that error to come up - I found it was the getOne() call because replacing it using getRow() instead worked.
When making a successful query to getOne() that returns rows, getOne() returns too early and never reaches the free() call. This results in MySQL throwing the error "Commands out of sync, you can't run the command now"
Specifically, the error is on line 212, here:
https://github.com/colshrapnel/safemysql/blob/master/safemysql.class.php#L212
The return statement means that $this->free($res) is never called if the query returned results, it should instead follow the other statements by storing the return value and returning after calling free().
The text was updated successfully, but these errors were encountered: