I delved into MySQLi last night (only used normal mysql_ before that) to call MySQL stored procedures as part of a calendar script on my site. The SP that loads calendar events and hyperlinks the days works perfectly each time by using $(mysqli)->query("call SP"). This SP takes no parameters and returns a set of rows.
I want to add, in the same script, the option to click on one of the days and show details of the event that day. As this is the same script, I want to use the same MySQLi connection, but each time I try, the return value of the query is a Boolean(false). The second SP takes the date as a parameter, and I've constructed it before the query() call. Printing it to the web page, and running it from the MySQL CLI yields the expected data, so the SP works, and the user is authorised to execute SPs.
Out of interest, I tried replacing the SP call with the SP contents in query(), and again received a 'false' return, so it seems to me that MySQLi is not allowing me to perform two queries on the same connection. I've done some tinkering and tried free() on the first result set, to no avail. As I expected, if I closed and reopened the MySQLi connection, I could call the SP, but this seems to be very inefficient. Is there a specific sequence to perform multiple MySQL calls (not simultaneously) on the same connection? I've searched but only vaguely, as I don't really know what to search for. Thanks.
PHP在同一个连接上调用第二个MySQL存储过程或查询?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- drfu29983 2011-01-21 12:21关注
You need to call next_result after each sproc call as stored procedures return 2 resultsets: the data and a counter resultset.
$db = new mysqli("localhost", "foo_dbo", "pass", "foo_db", 3306); $result = $db->query("call foo()"); $db->next_result(); // using sprocs have to do this before next call ! $result = $db->query("call bar()"); $db->next_result(); ...
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
- ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
- ¥15 nginx反向代理获取ip,java获取真实ip
- ¥15 eda:门禁系统设计
- ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
- ¥15 376.1电表主站通信协议下发指令全被否认问题
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥15 复杂网络,变滞后传递熵,FDA
- ¥20 csv格式数据集预处理及模型选择
- ¥15 部分网页页面无法显示!