我试图在使用 WAMP 运行的本地网页上遵循此示例。这是代码
<!DOCTYPE html>
<head>
<title>Testing SQL injection</title>
</head>
<body>
<?php
$link = mysql_connect('localhost:3306', 'root', 'St@ck0verflow');
if(!$link)
die('Could not connect: ' . mysql_error());
if(!mysql_select_db('opentarget', $link))//arguments are in revere order compared to mysqli
die('Could not select database');
// a good user's name
$name = "Onetwo";
$query = "SELECT * FROM customers WHERE username = '$name'";
echo "Normal: " . $query . "<br />";
$result = mysql_query($query);
echo "Result: <pre>";
print_r(mysql_fetch_row($result));
echo "</pre><br /><br />";
// user input that uses SQL Injection
$name_bad = "' OR 1'";
// our MySQL query builder, however, not a very safe one
$query_bad = "SELECT * FROM customers WHERE username = '$name_bad'";
$result = mysql_query($query);
// display what the new query will look like, with injection
echo "Injection: " . $query_bad.'<br />Result: <pre>';
print_r(mysql_fetch_row($result));
echo '</pre>';
echo '<br />Any errors? '.mysql_errno($link) . ": " . mysql_error($link);
?>
</body>
</html>
第一个查询按预期运行,但是当我打印第二个查询的结果时,它与第一个查询相同。我以为它会打印出表格的所有内容?具体是OR 1
做什么的?
我尝试从命令行直接在 MySQL 中运行错误查询,除非我做错了什么,否则我会得到空集(这与 PHP 中显示的结果不同)。