我的 SQL 查询是:
SELECT * FROM listings WHERE title LIKE '%Debbie\'s Pet Grooming%'
但是,当我运行此查询时,我没有得到任何结果。你能建议为什么。我的数据库表如下:
最佳答案
您的问题是您以某种方式设法在数据库中的值中获得了实际的反斜杠,因此您需要搜索它。尝试这个:
SELECT * FROM listings WHERE title LIKE '%Debbie\\\\\'s Pet Grooming%'
Demo on dbfiddle
来自 manual :
Because MySQL uses C escape syntax in strings (for example, “\n” to represent a newline character), you must double any “\” that you use in LIKE strings. For example, to search for “\n”, specify it as “\\n”. To search for “\”, specify it as “\\\\”; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.
关于php - MySQL通配符过滤特殊字符使用LIKE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59281622/