I have the following PHP/MySQL code:
function executeMultirowQuery($query) {
$result = mysql_query($query);
$table = array();
if ($result == false) {
$error = mysql_error();
echo $error;
} else {
while ($row = mysql_fetch_assoc($result)) {
$table[] = $row;
}
mysql_free_result($result);
}
return $table;
}
It basically executes the given query, and returns the result as a multi-dimensional array. The second call (and all subsequent calls) to this function result in a "Commands out of sync; you can't run this command now" error from MySQL.
Since I'm calling mysql_free_result() before I return I don't think its that I still have a request out there, but I can't think of any other reason it might be failing.
Any ideas?
EDIT: If it makes any difference, I'm using this function to call stored procedures like this:
function getGroups($groupTypeID) {
echo "getGroups";
$query = sprintf("CALL getGroups('%s');", mysql_real_escape_string($groupTypeID));
return $this->executeMultirowQuery($query);
}
This is typical of the way the executeMultirowQuery() function is used.
EDIT: Here is my connection code:
$this->link = mysql_connect($host, $user, $password);
$success = mysql_select_db($database);
if (!$this->link) {
die('Could not connect: ' . mysql_error());
}
Also, here is a sample query from the stored procedure:
CREATE DEFINER=`blah`@`blah` PROCEDURE `getGroups`(
IN inGroupTypeID INT )
BEGIN
SELECT * FROM `db`.`Groups`
WHERE GroupTypeID = inGroupTypeID;
END
Again, this is typical of how the function is being used. None of the stored procedures returns multiple results sets (which I understand doesn't work in PHP/MySQL).
}and not the free result call.Any way, why do you try to invent the wheel, are you in learning phase?