【发布时间】:2019-11-30 16:10:10
【问题描述】:
我正在尝试删除描述中没有快速聊天用户名的所有缓存项。在尝试转义短划线字符时,我一直遇到语法问题?
查询:
$cacheItems = CacheItem::whereRaw("description NOT LIKE '%'")
->whereRaw("description NOT LIKE '%????%'")
->whereRaw("description NOT LIKE '%???????? %'")
->whereRaw("description NOT LIKE '%???????? :%'")
->whereRaw("description NOT LIKE '%????????????????????????????????%'")
->whereRaw("description NOT LIKE '%sc\'%'")
->whereRaw("description NOT LIKE '%sc\_%' ESCAPE '\'")
->whereRaw("description NOT LIKE '%sc \- %' ESCAPE '\'")
->whereRaw("description NOT LIKE '%sc %'")
->whereRaw("description NOT LIKE '%sc:%'")
->whereRaw("description NOT LIKE '%scm %'")
->whereRaw("description NOT LIKE '%scm;%'")
->whereRaw("description NOT LIKE '%sc- %'")
->whereRaw("description NOT LIKE '%sc.%'")
->whereRaw("description NOT LIKE '%sc-%'")
->whereRaw("description NOT LIKE '%SC - %'")
->whereRaw("description NOT LIKE '%Sc ~%'")
->whereRaw("description NOT LIKE '%sc ~%'")
->whereRaw("description NOT LIKE '%sc;%'")
->whereRaw("description NOT LIKE '%sc~%'")
->whereRaw("description NOT LIKE '%sc/%'")
->whereRaw("description NOT LIKE '%snapchat:%'")
->whereRaw("description NOT LIKE '%snapchat - %'")
->whereRaw("description NOT LIKE '%snapchat-%'")
->whereRaw("description NOT LIKE '%snap~%'")
->whereRaw("description NOT LIKE '%snap =%'")
->whereRaw("description NOT LIKE '%snap•%'")
->whereRaw("description NOT LIKE '%snap%'")
->whereRaw("description NOT LIKE '%snap~%'")
->whereRaw("description NOT LIKE '%snapchat%'")
->whereRaw("description NOT LIKE '%snapchat ~ %'")
->whereRaw("description NOT LIKE '%snap:%'")
->whereRaw("description NOT LIKE '%add my sc%'")
->whereRaw("description NOT LIKE '%add me on sc%'")
->whereRaw("description NOT LIKE '%add me sc%'")
->whereRaw("description NOT LIKE 'snap %'")
->get();
错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%sc \- %' ESCAPE '\' and description NOT LIKE '%sc %' and description NOT LIKE '' at line 1 (SQL: select * from `cache_items` where description NOT LIKE '%' and description NOT LIKE '%????%' and description NOT LIKE '%???????? %' and description NOT LIKE '%???????? :%' and description NOT LIKE '%????????????????????????????????%' and description NOT LIKE '%sc\'%' and description NOT LIKE '%sc\_%' ESCAPE '\' and description NOT LIKE '%sc \- %' ESCAPE '\' and description NOT LIKE '%sc %' and description NOT LIKE '%sc:%' and description NOT LIKE '%scm %' and description NOT LIKE '%scm;%' and description NOT LIKE '%sc- %' and description NOT LIKE '%sc.%' and description NOT LIKE '%sc-%' and description NOT LIKE '%SC - %' and description NOT LIKE '%Sc ~%' and description NOT LIKE '%sc ~%' and description NOT LIKE '%sc;%' and description NOT LIKE '%sc~%' and description NOT LIKE '%sc/%' and description NOT LIKE '%snapchat:%' and description NOT LIKE '%snapchat - %' and description NOT LIKE '%snapchat-%' and description NOT LIKE '%snap~%' and description NOT LIKE '%snap =%' and description NOT LIKE '%snap•%' and description NOT LIKE '%snap%' and description NOT LIKE '%snap~%' and description NOT LIKE '%snapchat%' and description NOT LIKE '%snapchat ~ %' and description NOT LIKE '%snap:%' and description NOT LIKE '%add my sc%' and description NOT LIKE '%add me on sc%' and description NOT LIKE '%add me sc%' and description NOT LIKE 'snap %')
【问题讨论】:
-
您是否使用了特殊字符?
Sc看起来很有趣。 -
你用的是什么框架?而且您的
SQL声明也是错误的。 -
Laravel 框架,我明白我的说法是错误的 - 你能帮我找出原因吗?
-
\-是什么意思?在 PHP 中无效,1:1 复制。所以mysql会抛出一个错误。 -
mysql 不喜欢 ESCAPE '\'
标签: php mysql escaping sql-like