duanfu7004 2016-05-11 11:33
浏览 41

MySQL存储过程和PHPMyAdmin

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条回答 默认 最新

  • dppfxf909679 2016-05-11 11:48
    关注

    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.
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?