What is the difference between mysql_real_escape_string and addslashes?

后端 未结 5 1342
野性不改
野性不改 2020-12-31 15:32

mysql_real_escape_string and addslashes are both used to escape data before the database query, so what\'s the difference? (This question is not ab

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 15:47

    string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )
    mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

    string addslashes ( string $str )
    Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).

    They affect different characters. mysql_real_escape_string is specific to MySQL. Addslashes is just a general function which may apply to other things as well as MySQL.

提交回复
热议问题