MySQL escape characters are symbols or combinations used to represent special characters in MySQL. These symbols can be used to protect data from being misinterpreted as part of an SQL statement. The use of MySQL escape characters is very simple, but they should be used with care when writing SQL statements. This article will introduce some common MySQL escape characters.
SELECT * FROM users WHERE name = 'Tom';
If there is a single quote in the name, such as "Tom's Restaurant", it needs to be escaped with a backslash:
SELECT * FROM users WHERE name = 'Tom's Restaurant';
Similarly, if we need to If you use double quotes in a string, you need to escape it with a backslash:
SELECT * FROM users WHERE description = "This is a "very nice" restaurant";
SELECT * FROM users WHERE name LIKE 'T%';
This query will return all names starting with "T". In this case, the percent sign is used as a wildcard to match a string of any length. If we want to find all names starting with "TOM", we can use the following query:
SELECT * FROM users WHERE name LIKE 'TOM%';
SELECT * FROM users WHERE name LIKE '__';
Note that in this case, the double underscore is used as a wildcard to match any two letters. character string.
The above is the detailed content of mysql escape character. For more information, please follow other related articles on the PHP Chinese website!