我已经创建了创建多个表并插入数据的 MySql 过程,如果数据不是最新的,则将其删除并在 mysql 命令行或我的 sql workbench 中显示消息。为此,我使用变量然后显示如下它在 mysql 中运行良好。
SET _output = 'Generating table one...';
select _output;
create table ec_ms_yy_qt
(select * from table1);
call checkdata();
SET _output = 'Generating table tow..';
select _output;
如果我从 php 调用它,它会在第一个语句后停止并且不执行该过程。 它只返回'生成表一......'; .意思是找到select语句就停止运行
$rs = mysql_query( ‘CALL processdata()’ );
while($row = mysql_fetch_assoc($rs))
{
print_r($row);
}
然后我从存储过程中删除了 select _output,它工作正常。但这不是我想要的解决方案,用户不会收到任何错误发生和错误发生的通知。它还挂起程序,直到程序完成并在状态栏上浏览显示等待本地主机。
最佳答案
这是 PHPs MySQL 扩展的一个特性,试图阻止 SQL injection (在某种程度上)。请注意 mysql
PHP 中的扩展已弃用,不再维护,在编写新的 PHP 脚本时不应使用。 deprecation is documented在手册中。 mysql_query()
上的文档也明确指出:
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
请注意新的 mysqli
extension 是原始 mysql
extension 的替代品,具有允许在一个查询字符串中包含多个语句的特殊功能:mysqli_multi_query()
关于php - 不能在一个查询中运行多个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800507/