php用mysql_query()调用存储过程后无法再执行sql报错:commands out of sync you can't run this command now
2015-01-30 16:54
921 查看
我遇到了这个问题,困扰了两天,google、百度之,皆言使用mysqli的方法能解决,但是造成问题的原因没人能说清楚,我寻找各种方法企图弄明白真相,偶然间在PHPMyAdmin中执行带输出参数存储过程发现了问题所在:MySQL带输出参数的存储过程执行完成后系统会自动执行一条select @outValue=out参数 的语句
1 如果在MySQL的存储过程中存在两个及以上独立select语句会造成此问题
原因是php的mysql_query()只能用于一个结果集,因为存储过程中多个独立select语句都要给mysql_query()赋结果集,便导致php的后续
mysql_query()出错。
2 MySQL存储过程带有输出参数且使用了独立select语句也会造成此问题
这是因为MySQL带输出参数的存储过程执行完成后会由系统自动执行一条select @outValue=out参数 的语句,此时便有两条及以上独立
select语句要给只能用于一个结果集的php的mysql_query()赋结果集,使后续mysql_query()出错。
对此,解决办法就是MySQL存储过程中不要使用独立select语句,
或者使用mysqli的方式来执行。
1 如果在MySQL的存储过程中存在两个及以上独立select语句会造成此问题
原因是php的mysql_query()只能用于一个结果集,因为存储过程中多个独立select语句都要给mysql_query()赋结果集,便导致php的后续
mysql_query()出错。
2 MySQL存储过程带有输出参数且使用了独立select语句也会造成此问题
这是因为MySQL带输出参数的存储过程执行完成后会由系统自动执行一条select @outValue=out参数 的语句,此时便有两条及以上独立
select语句要给只能用于一个结果集的php的mysql_query()赋结果集,使后续mysql_query()出错。
对此,解决办法就是MySQL存储过程中不要使用独立select语句,
或者使用mysqli的方式来执行。
相关文章推荐
- PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now
- PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now 问题的解决
- PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now
- MySQL一次执行多条语句的实现及常见问题(C API Commands out of sync; you can't run this command now)
- PHP+MySQL连续插入数据报错:Commands out of sync; you can't run this command now & 读取Excel数据并批量插入到数据中
- python mysql 2014 Commands out of sync; you can't run this command now
- 解决error:2014 Commands out of sync; you can't run this command now
- 解决error:2014 Commands out of sync; you can't run this command now
- Commands out of sync; you can't run this command now
- LR错误: Commands out of sync; you can't run this command now 解决方法
- C++ Mysql调用 错误:2014 :Commands out of sync; you can't run this command now
- MySQL一次执行多条语句的实现及常见问题(C API Commands out of sync; you can't run this command now)
- 解决error:2014 Commands out of sync; you can't run this command now
- error:2014 Commands out of sync; you can't run this command now
- 解决mysql error:2014 Commands out of sync; you can't run this command now
- Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES解决方案
- mysql 出现 Commands out of sync; you can't run this command now
- mysql: Commands out of sync; you can't run this command now
- python Commands out of sync; you can't run this command now
- Commands out of sync; you can't run this command now SQL