mysql - 这个SQL注入(inject)不行,为什么?

标签 mysql sql-injection

我正在尝试一种 SQL 注入(inject):

http://localhost/test/mysql.php?uid=1;%20DROP%20TABLE%20test

此 URL 应等于语句:

SELECT username FROM test WHERE userid=1; DROP TABLE test

但是,当我打开这个 URL 时弹出一个错误:

Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'drop table test' at line 1

'drop table test' 好像是放在一对引号里,但不被当做语句。对应的php代码是这样的:

$SQL="select username from login where userid=".$userid;
$result=mysql_query($SQL);

我想知道为什么。感谢您提供任何有用的答案。

最佳答案

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.

MySQL 错误消息也反射(reflect)了这一点,该消息将 ; 之后的所有内容都引用为意外。

关于mysql - 这个SQL注入(inject)不行,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24902663/

相关文章:

php - MySQL查询结果不是资源

sql - rails find_by sql 注入(inject)

php - 我的 PHP 代码中的 SQL 注入(inject)

javascript - 防止 JavaScript/Node.js 中的 SQL 注入(inject)

php - 此用户表单的潜在安全问题

sql-injection - SQL 注入(inject)和两个查询

用于多种条件的php sql语句正确方法

javascript - PHP JOIN查询调整产品状态但无法解决

python - 如何编写正则表达式以特定字符串开头和结尾?

php - 更新 php pdo 中的上次登录 session