From a665ee1e08d78aba9c62674e10123e7f415e0263 Mon Sep 17 00:00:00 2001 From: Aidan Lister Date: Wed, 11 Aug 2004 10:03:20 +0000 Subject: [PATCH] Removed initial example Added a massive example with information about sql injection attacks Added more information to the % and _ note Added a variablelist git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@166030 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../functions/mysql-real-escape-string.xml | 132 +++++++++++++++--- 1 file changed, 109 insertions(+), 23 deletions(-) diff --git a/reference/mysql/functions/mysql-real-escape-string.xml b/reference/mysql/functions/mysql-real-escape-string.xml index b2213e8bc1..a607dcb5d8 100644 --- a/reference/mysql/functions/mysql-real-escape-string.xml +++ b/reference/mysql/functions/mysql-real-escape-string.xml @@ -1,11 +1,12 @@ - + mysql_real_escape_string - Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection. + Escapes special characters in a string for use in a SQL statement, + taking into account the current charset of the connection. @@ -15,47 +16,132 @@ stringunescaped_string resourcelink_identifier + + + + unescaped_string + The string to escape + + + + link_identifier (optional) + The mysql connection resource + + + This function will escape special characters in the unescaped_string, taking into account the current charset of the connection so that it is safe to place it in a - mysql_query. + mysql_query. If you wish to insert binary data + you must use this function. + + + mysql_real_escape_string calls MySQL's library function of the + same name, which prepends slashes to the following characters: + NULL, \x00, \n, + \r, \, ', + " and \x1a. + + + You must always (with few exceptions) use this function + to make your data safe before inserting. If you have + magic_quotes_gpc enabled, + you must first stripslashes your data. If you don't use + this, you'll leave yourself open to SQL Injection Attacks. Here's an example: - - - mysql_real_escape_string does not escape - % and _. - - - <function>mysql_real_escape_string</function> example + An example SQL Injection Attack +]]> + + + The query sent to MySQL: + + + + + + This would allow anyone to log in without a valid password! Using + mysql_real_escape_string around each variable + prevents this. + + + ]]> - The above example would produce the following output: + Our query is now safe no matter what the user submits! - - - + + + mysql_real_escape_string does not escape + % and _. These are wildcards in MySQL + if not bounded by quotes. + + See also - mysql_escape_string, mysql_client_encoding, addslashes, and the magic_quotes_gpc