Why do we escape strings?
#2

It's to prevent SQL injection.

Enter "DROP TABLE `accounts`" on a dialog that processes a query. Try it out (but take caution on what it does).

http://www.w3schools.com/sql/sql_injection.asp

First thing you'll notice beyond that link:

An SQL Injection can destroy your database.

I think that's pretty clear and explains why you should escape strings on queries.

By the way, use the specifier "%q" on the function "format" to escape a string. This would be replaced for the specifier "%s".
Reply


Messages In This Thread
Why do we escape strings? - by SystemX - 22.01.2016, 03:24
Re: Why do we escape strings? - by SickAttack - 22.01.2016, 03:28
Re: Why do we escape strings? - by SystemX - 22.01.2016, 03:36
Re: Why do we escape strings? - by Jack_SMalls - 22.01.2016, 04:06
Re: Why do we escape strings? - by SystemX - 22.01.2016, 04:22

Forum Jump:


Users browsing this thread: 1 Guest(s)