Home >Backend Development >PHP Tutorial > 关于PDO里自动转义的有关问题

关于PDO里自动转义的有关问题

WBOY
WBOYOriginal
2016-06-13 13:10:531378browse

关于PDO里自动转义的问题
我看书上说如果采用prepare 和execute 方法,还可以防止SQL 注入等攻击。因为所有的变量都会
被自动转义。
然后我在表单中输入df'dfdf",结果不能输入数据。
SQL语句:INSERT INTO cms_manage( admin_user, admin_pass, level, last_time ) VALUES( 'df'dfdf"', 'da39a3ee5e6b4b0d3255bfef95601890afd80709', '6', NOW() )
错误信息:SQLSTATE[42000]: Syntax error or access violation: 1064 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 'dfdf"', 'da39a3ee5e6b4b0d3255bfef95601890afd80709', ' at line 9
当我把数据df'dfdf"用mysql_real_escape_string函数转义后,就成功了,到底prepare 和execute能不能自动转义了,是不是还要手动转义。

------解决方案--------------------
当然能!
不过你只贴出了 sql 指令,并没用有 prepare 和 execute 方法
------解决方案--------------------
我认为是你代码的问题,PDO的prepare() execute()组合的确能预防SQL注入。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn