What characters have to be escaped to prevent (My)SQL injections?

前端 未结 6 832
温柔的废话
温柔的废话 2020-11-29 05:47

I\'m using MySQL API\'s function

mysql_real_escape_string()

Based on the documentation, it escapes the following characters:



        
6条回答
  •  心在旅途
    2020-11-29 06:09

    A guess concerning the backspace character: Imagine I send you an email "Hi, here's the query to update your DB as you wanted" and an attached textfile with

    INSERT INTO students VALUES ("Bobby Tables",12,"abc",3.6);
    

    You cat the file, see it's okay, and just pipe the file to MySQL. What you didn't know, however, was that I put

    DROP TABLE students;\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
    

    before the INSERT STATEMENT which you didn't see because on console output the backspaces overwrote it. Bamm!

    Just a guess, though.

    Edit (couldn't resist):

    alt text

提交回复
热议问题