一个 mysql_query() 查询中的 PHP 多个 MYSQL 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11106719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP multiple MYSQL commands in one mysql_query() query
提问by Matthias Dunnowa
I want to issue multiple mysql commands with one mysql_query function. This is my code:
我想用一个 mysql_query 函数发出多个 mysql 命令。这是我的代码:
$query .= "INSERT INTO `users` VALUES(1,'stack','overflow');";
$query .= "INSERT INTO `posts` VALUES('other','stack','overflow');";
mysql_query($query);
If I do that I get a warning that my syntax would be incorrect. If I echo the output, copy it and execute it in phpMyAdmin it works.
如果我这样做,我会收到一条警告,指出我的语法不正确。如果我回显输出,复制它并在 phpMyAdmin 中执行它就可以了。
Where is the error there?
错误在哪里?
回答by Jay
$query = "INSERT INTO `users` VALUES (1,'stack','overflow'), ('other','stack','overflow');";
mysql_query($query);
PHP does not support sending more than one query at a time via mysql_query, but you can achieve your result in a single one by using the above.
PHP 不支持通过 一次发送多个查询mysql_query,但您可以使用上述方法在单个查询中获得结果。
回答by Don
I think you need this?? http://us2.php.net/manual/en/mysqli.multi-query.php
我想你需要这个??http://us2.php.net/manual/en/mysqli.multi-query.php
回答by Fivell
according to http://www.php.net/manual/en/function.mysql-querymysql_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.
根据http://www.php.net/manual/en/function.mysql-querymysql_query() 向与指定 link_identifier 关联的服务器上的当前活动数据库发送唯一查询(不支持多个查询)。
but this guy said that you just have to pass flag 65536 as mysql_connect's 5 parameter http://www.php.net/manual/en/function.mysql-query.php#91669
但是这家伙说你只需要将标志 65536 作为 mysql_connect 的 5 参数传递 http://www.php.net/manual/en/function.mysql-query.php#91669

