0

I have created a procedure (with the PHPMyAdmin tool) which returns a table and two outputs. If I execute the procedure with the button "Execute" of PHPMyAdmin it sends this query:

SET @p0 =  '12';
SET @p1 =  '1';
CALL `getPhoneReview` (@p0 , @p1 , @p2 , @p3);
SELECT @p2 AS  `PhoneCount` , @p3 AS  `ReviewCount`;

Which returns what is expected (the table and the two outputs). However, if I copy that exact code and execute from the SQL section it only executes the last sentence:

CALL `getPhoneReview` (@p0 , @p1 , @p2 , @p3)

Which doesn't return anything.

It's happening as well while trying to retrieve the output values with PHP. I have this code:

$C = new MySQLi(...);
$Q = $C->query("CALL getPhoneReview(12, 1, @PhoneCount, @ReviewCount)");
/* Looping over $Q works fine */
$PhoneCount = $C->query("SELECT @PhoneCount AS PhC");
$PCO = $PhoneCount->fetch_object();
var_dump($PCO->PhC); /*  Call to a member function fetch_object() on boolean */

Could anybody help me?

1 Answers1

1

There are two problems with your code.

  • First, there is no proper error reporting for mysqli in your code, and you have only a notice from PHP, but not a real error from mysql. You may read how to make it properly here.
  • Second, after calling a stored procedure, you should always call $C->next_result(); in order to let other queries to be executed.
Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Adding $C->next_result() after the loop solved the problem. Thank you! –  May 11 '16 at 11:51