gpt4 book ai didi

php - MySQL通配符过滤特殊字符使用LIKE

转载 作者:行者123 更新时间:2023-12-04 23:32:37 28 4
gpt4 key购买 nike

我的 SQL 查询是:

SELECT * FROM listings  WHERE title LIKE '%Debbie\'s Pet Grooming%' 

但是,当我运行此查询时,我没有得到任何结果。你能建议为什么。我的数据库表如下:

enter image description here

最佳答案

您的问题是您以某种方式设法在数据库中的值中获得了实际的反斜杠,因此您需要搜索它。尝试这个:

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com