I was looking through the docs and stumbled onto mysql_real_escape_string() and I'm not understanding why it's useful when you can just addslashes(). Can someone show me a scenario as to why it's useful?
I'm also curious why it requires a database connection.... that seems like a lot of overhead.
Nether mysql_real_escape_string() or addslashes() prevent everything (what about xss or even xsrf?), and most importantly nether of them prevent all SQL Injection.
For instance this code is vulnerable to sql injection:
Exploit:
patch:
Use parametrized queries with either ADODB or PDO, this is the only bullet proof sql injection protection.
There is a great article about this here. And this discussion also points out the pros and cons of each solution.