MYSQL - What all do I need to escape when sending a (My)SQL query?

When you execute a SQL query, you have to clean your 'strings' or users can execute malicious SQL on your website.

I usually just have a function escape_string(blah), which:

  • Replaces escapes () with double escapes (\).
  • Replaces single quotes (') with an escaped single quote (\').

Is this adequate? Is there a hole in my code? Speedy library to reliably do this for me?

I'd like to see graceful solutions in:

  • Perl
  • Java
  • PHP
This question and answers originated from www.stackoverflow.com
Question by (8/5/2008 6:45:46 PM)

Answer

For maximum security, performance, and correctness use prepared statements. Here's how to do this with lots of examples in different languages, including PHP:

http://efreedom.com/Question/1-1973/what-is-the-best-way-to-avoid-sql-injection-attacks

Answer by

Find More Answers
Related Topics  mysql  sql  security
Related Questions