CREATE PROCEDURE test1()
begin
drop table if exists tb1;
create table tb1
(
val int not null
)engine = innoDB;
insert into tb1(val) values(1),(2),(3);
select * from tb1;
end
$mysqli = new mysqli("localhost", "root", "sbqcel", "test");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = null;
$mysqli->autocommit(FALSE);
if(!($result = $mysqli->query( "call test1();")))
{
echo mysqli_error($link);
$mysqli->rollback();
}
$mysqli->commit();
print 'Result1:';
while ($row = $result->fetch_row())
{
printf ("%s <br />", $row[0]);
}
$result->close();
mysqli_free_result($result);
echo 'result2:<br />';
if ($result2 = $mysqli->query("select val from tb1;"))
{
while ($row = $result2->fetch_row())
{
printf ("%s <br />", $row[0]);
}
$result2->close();
}
else
{
echo $mysqli->error;
}
mysqli_free_result($result2);
mysqli_close($link);
执行上面的代码后就会出现上面的错误,消息说明MYSQL数据库认为是这一个错误的命令执行顺序。原因在于MYSQL的存储过程执行完成后除了返回实际结果集还会返回存储过程执行的转态
,而上面的代码仅处理了第一个结果集,第二个结果集并没有被释放掉。
When a stored procedure returns a resultset, MySQL returns at least two resultsets: first for the SELECT CALL inside the stored procedure. 2ndfor the call of the stored procedure itself
(2nd usually is only an OK or ERR packet).
要解决这个问题,需要用mysqli的multi_query方法,遍历所有的结果集并释放掉掉。代码如下:
<?php
$mysqli = new mysqli("localhost", "root", "sbqcel", "test");
$mysqli->multi_query("set names 'utf8'");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
echo 'result1:<br />';
$mysqli->autocommit(FALSE);
if ($mysqli->multi_query("call test1();"))
{
do {
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->close();
}
} while ($mysqli->next_result());
}
$mysqli->commit();
echo "<br />";
echo "result2:<br />";
if ($result2 = $mysqli->query("select val from tb1;"))
{
while ($row = $result2->fetch_row()) {
printf ("%s <br />", $row[0]);
}
$result2->close();
}
else
{
echo $mysqli->error;
}
$mysqli->close();
?>
分享到:
相关推荐
you can't run this command now"错误是一个常见的问题,它通常出现在多条语句连续执行时,由于某些原因导致数据连接的状态不一致,使得MySQL无法正确处理后续的命令。这个错误的根源在于MySQL的C API,当执行...
问题 mysql 查询出现错误 ... you can’t run this command now in your client code, you are calling client functions in the wrong order. This can happen, for example, if you are using mysql
原来是必须取得result,并执行result.Close()。原理是什么? 2020.10.26 照着的套路,用Go+Gin 把后台的部分重写了一遍,搞了两天才能正确跑起来。这个部分移出到独立的repo 继续做。 go get 扫雷: 中国大陆用go get...
MySQL是支持在单个查询字符串中指定多语句执行的,使用方法是给链接指定参数: 代码如下: //链接时设定 mysql_real_connect( …, CLIENT_MULTI_STATEMENTS ... you can’t run this command now 官方推荐的执行语句是这
在开发过程中,你可能还会遇到数据库连接丢失或在远程服务器上部署Django项目时同步数据库报错的情况。确保正确配置数据库连接参数、检查网络连接、以及遵循服务器安全策略都是解决这些问题的关键步骤。 总之,正确...
help 命令的最大参数数是 CONFIG_SYS_MAXARGS,是否允许重复执行是 1,执行函数是 do_help,使用信息是 "print command description/usage",详细使用信息是 "- print brief description of all commands\n help ...
MySqlCommand:执行一条sql语句。 MySqlDataReader: 包含sql语句执行的结果,并提供一个方法从结果中阅读一行。 MySqlTransaction: 代表一个SQL事务在一个MySQL数据库。 MySqlException: MySQL报错时返回的Exception...
pycharm中导入模块错误时,提示:Try to run this command from the system terminal. Make sure that you use the correct version of ‘pip’ installed for your Python interpreter located atpycharm工作路径。...
MySQL中的CASE语句是SQL语言中的一个重要组成部分,它在存储过程和复杂查询中扮演着条件判断的角色,使得代码更加简洁易读。CASE语句提供了两种形式:简单CASE和可搜索CASE。 1. 简单CASE语句: 简单CASE语句主要...
Welcome to the Command Reference.This reference contains a complete dictionary of detailed command descriptions, arranged in alphabetical order. It is the definitive resource for correct command ...
The LLDB command command regex acts much like command alias, except you can provide a regular expression for input which will be parsed and applied to the action part of the command. 10. Assembly ...
You don't need to run idf.py build before running idf.py flash, idf.py flash will automatically rebuild anything which needs it. Viewing Serial Output The idf.py monitor target uses the idf_monitor ...
`mysqlcommand`是一个方便的工具,它为Laravel提供了更便捷的方式来使用MySQL命令行工具,使得开发者无需离开命令行环境即可执行常见的MySQL管理任务。这个压缩包文件`mysql-command-master`很可能包含了一个用于...
telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss 老师测评网址 http://172.16.0.198:8080/poll/ 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ 一、注意...
It can be run in interactive mode, or can automatically parse a list of commands from a file. Example LSql queries are: SELECT field1,field2 WHERE +field1:value This command will display two ...
在项目下执行如下命令 php think build admin 报如下图错误 解决办法: 1.查看官方文档: https://www.kancloud.cn/manual/thinkphp6_0/1037643 文档里说: 所以我命通过命令安装扩展: composer require ...
November 13 2017:Can't run Cheat Engine There is apparently some malware going around that blocks execution of Cheat Engine (Saying file missing, check filename, etc...) If you have been a victim of ...