From:  pear-qa@lists.php.net ("trparky@toms-world.org")
Date:  25 Dec 2015 09:39:23 Hong Kong Time
Newsgroup:  news.php.net/php.pear.bugs
Subject:  

[PEAR-BUG] Bug #20975 [Com]: Unable to execute another query after calling a MySQL Stored Procedure

NNTP-Posting-Host:  null

Edit report at https://pear.php.net/bugs/bug.php?id=20975&edit=1

 ID:               20975
 Comment by:       trparky@toms-world.org
 Reported By:      trparky at toms-world dot org
 Summary:          Unable to execute another query after calling a MySQL
                    Stored Procedure
 Status:           Feedback
 Type:             Bug
 Package:          DB
 Operating System: Linux
 Package Version:  1.8.2
 PHP Version:      5.4.45
 Roadmap Versions: 
 New Comment:

If I make a query against the database using a stored procedure, in my
case I use the following code...

$counterQuery = $db->query("CALL getSpecificDownloadCounter(?, ?);",
array($counterName, $fileFolder));

if ($counterQuery->numRows() != 0) {
	$result = $db->query("CALL advanceDownloadCounter(?, ?);",
array($counterName, $fileFolder));
	if (PEAR::isError($result)) die($result->getMessage());
}

The isError line will return "DB Error: no database selected". If I add
the following line of code to mysqli.php...

if (preg_match('/\ACALL.*/im', $query))
$this->connection->next_result();

Right after...
$result = @mysqli_query($this->connection, $query);
On line 400, the next query I make executes properly.

According to MySQL documentation, if you execute a stored procedure you
must execute next_result() or the next query will fail.


Previous Comments:
------------------------------------------------------------------------

[2015-11-24 14:20:30] danielc

-Status: Open
+Status: Feedback
Hi Tom:

Thank you for the patch.  Please upgrade DB to version 1.9.2 without the
patch.  If the problem persists, please write a short reproduce script
that makes a connection, creates a sample database and stored procedure,
executes the stored procedure then drops the database.

--Dan

------------------------------------------------------------------------

[2015-10-28 22:35:10] trparky

I have provided a patch file to fix this issue.

------------------------------------------------------------------------

[2015-10-28 22:33:02] trparky

Added #patch bug:20975;patch:mysqli.patch;revision:1446071582;.

------------------------------------------------------------------------

[2015-10-28 22:15:05] trparky

Description:
------------
After calling a MySQL Stored Procedure in MySQLi mode, you are unable to
execute another query after it. When you try to it tells you that you
have no database selected.

In order to fix this issue, you must patch mysqli.php file and add this
line...
if (preg_match('/\ACALL.*/im', $query))
$this->connection->next_result();
After this line (line 400)...
$result = @mysqli_query($this->connection, $query);

------------------------------------------------------------------------


-- 
Edit this bug report at https://pear.php.net/bugs/bug.php?id=20975&edit=1