Note one of PHPmysql_real_escape_string. The mysql_real_escape_string () function escapes special characters in strings used in SQL statements. The following characters are affected: if x00nrx1a succeeds, the function returns the special characters in the escape character mysql_real_escape_string () to escape the strings used in the SQL statement.
The following characters are affected:
If yes, the function returns the escaped string. If it fails, false is returned.
Use mysql_real_escape_string (string, connection)
- The string parameter, required. Specifies the string to be escaped.
- The connection parameter. optional. MySQL connection is required. If not specified, use the previous connection.
This function escapes special characters in string and considers the connected current character set. Therefore, it can be safely used for mysql_query (). This function is used to prevent database attacks.
Simple use of mysql_real_escape_string ()
SQL injection (mysql_real_escape_string () is not used ())
Database attacks. This example shows what will happen if we do not apply the mysql_real_escape_string () function to the user name and password:
The SQL query will be like this:
SELECT * FROM usersWHERE user='john' AND password='' OR ''=''
This means that any user can log on without entering a valid password.
The correct method to prevent database attacks:
Some experiences
Mysql_escape_string () also achieves similar results. For these two functions, remember that when I use the mysql_real_escape_string () function, the program always fails and I don't know the cause of the error. then I changed it to the mysql_escape_string () function. Find the manual and find that when mysql_real_escape_string () is used, you must first establish a database connection; otherwise, the error-___-|
Mysql_real_escape_string () CILS MySQL's library function mysql_escape_string, which prepends backslashes to the following characters: NULL, x00, n, r, ', "and x1a
Mysql_escape_string () does not escape % and _.
This function is identical to mysql_real_escape_string () handle T that mysql_real_escape_string () takes a connection handler and escapes the string according to the current character set. mysql_escape_string () does not take a connection argument and does not respect the current charset setting.
The http://www.bkjia.com/PHPjc/752406.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/752406.htmlTechArticlemysql_real_escape_string () function escapes special characters in strings used in SQL statements. The following characters are affected: if x00 n r'x1a is successful, the function returns the escape character...