简体   繁体   中英

Is mysql_real_escape_string enough to Anti SQL Injection?

In PHP Manual, there is a note:

Note: If this function is not used to escape data, the query is vulnerable to SQL Injection Attacks.

Is this enough to anti sql injection? If not, could you give an example and a good solution to anti sql injection?

mysql_real_escape_string is usually enough to avoid SQL injection. This does depend on it being bug free though, ie there's some small unknown chance it is vulnerable (but this hasn't manifested in the real world yet). A better alternative which completely rules out SQL injections on a conceptual level is prepared statements . Both methods entirely depend on your applying them correctly; ie neither will protect you if you simply mess it up anyway.

据我所知,这是避免SQL注入攻击的可靠方法。

The best solution is PDO .

If you're using the traditional mysql_query then running all of your data through mysql_real_escape_string() is enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM