这是在运行数据库查询之前防止SQL注入的好方法吗?使用mysql_real_escape_string和stripslashes避免SQL注入
$name = mysql_real_escape_string(stripslashes($name));
$age = mysql_real_escape_string(stripslashes($age));
$location = mysql_real_escape_string(stripslashes($location));
在此先感谢!
为什么你需要'stripslashes'以及如何使用[PDO](http://php.net/manual/en/book.pdo.php)? – 2012-02-22 11:34:55
简短的回答 - 不,不是。不要使用'mysql_ *'函数,但使用PDO,就像@Click建议的那样。 – 2012-02-22 11:38:42
你的代码打破了最近/正确配置(魔术引号禁用)PHP安装中包含反斜杠的任何字符串。切勿无条件使用'stripslashes'。只有当'get_magic_quotes_gpc()'存在并返回'true'时才使用它! – ThiefMaster 2012-02-22 12:27:12