If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection , like in the following example: 若是将用户输入未经修改地插入到SQL查询中,则应用程序容易受到SQL注入的攻击,如如下示例所示: php
$unsafe_variable = $_POST['user_input']; mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");
That's because the user can input something like value'); DROP TABLE table;--
这是由于用户能够输入相似value'); DROP TABLE table;--
value'); DROP TABLE table;--
, and the query becomes: value'); DROP TABLE table;--
,查询变为: mysql
INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')
What can be done to prevent this from happening? 如何防止这种状况的发生? sql