无法在 PHP 中一次执行两个 mysql 查询 [英] Cannot execute two mysql queries at once in PHP

查看:45
本文介绍了无法在 PHP 中一次执行两个 mysql 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试通过用分号分隔来一次执行两个 MySQL 查询,它在 PHP MyAdmin 中运行良好,但查询在 PHP mysql_query() 中根本不起作用.

If I try to execute two MySQL queries at once by delimiting them with a semicolon, it works fine in PHP MyAdmin, but the query doesn't work at all in PHP mysql_query().

有人知道为什么吗?

推荐答案

mysql_query 一次只允许您进行一个查询.这有助于防止 SQL 注入.

mysql_query only allows you to make one query at a time. This helps prevent SQL injection.

来自文档:

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.

如果您要做的是确保两个查询在一个事务中运行,请查看 这篇文章关于使用 PHP 和 MySQL 进行事务控制.

If what you're trying to do is make sure that the two queries run in one transaction, check out this article on transaction control with PHP and MySQL.

这篇关于无法在 PHP 中一次执行两个 mysql 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆