diff --git a/reference/mysql/functions/mysql-real-escape-string.xml b/reference/mysql/functions/mysql-real-escape-string.xml index bacb4ff3c7..bc5d18135b 100644 --- a/reference/mysql/functions/mysql-real-escape-string.xml +++ b/reference/mysql/functions/mysql-real-escape-string.xml @@ -1,5 +1,5 @@ - + @@ -32,8 +32,8 @@ This function will escape special characters in the unescaped_string, taking into account the current character set of the connection so that it is safe to place it in a - mysql_query. If you wish to insert binary data - you must use this function. + mysql_query. If binary data is to be inserted, this function + must be used. mysql_real_escape_string calls MySQL's library function @@ -62,15 +62,19 @@ $query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'", - You must always (with few exceptions) use this function to make your data - safe before sending a query to MySQL. If you have - magic_quotes_gpc enabled, - and you are working with data from user input, you must first - stripslashes your data. If your data are form other - sources and you have - magic_quotes_runtime enabled, you also have to - stripslashes your data. If you don't do so, you leave - yourself open to SQL Injection Attacks. Here's an example: + This function must always (with few exceptions) be used to make data + safe before sending a query to MySQL. + + + + If magic_quotes_gpc is enabled, + first apply stripslashes to the data. Using this function + on data which has already been escaped will escape the data twice. + + + + If this function is not used to escape data, the query is vulnerable to + SQL Injection Attacks. @@ -100,28 +104,27 @@ SELECT * FROM users WHERE name='aidan' AND password='' OR 1=1 ]]> - This would allow anyone to log in without a valid password! Using - mysql_real_escape_string around each variable - prevents this. + This would allow anyone to log in without a valid password. + + + Using mysql_real_escape_string around each variable + prevents this. This example demonstrates the proper method for querying a database, + independent of the Magic Quotes setting. - The query will now execute correctly, and Injection attacks will no longer work. + The query will now execute correctly, and SQL Injection attacks will not work.