且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 mysql、php 和 pdo 选择不区分大小写

更新时间:2022-12-18 12:05:23

这个

...snip... ) LIKE '%' LOWER(:wildcard) '%' OR ...snip

不正确.您有一个字符串 ('%') 后跟一个函数调用 (LOWER()) 后跟另一个字符串,它们只是坐在那里 - 没有连接逻辑,没有串联,等等等等.

is incorrect. You've got a string ('%') followed by a function call (LOWER()) followed by another string, and they're just sitting there - no connecting logic, no concatenation, blah blah blah .

应该是

... LIKE CONCAT('%', LOWER(:wildcard), '%') OR ...

默认情况下,mysql 比较不区分大小写,除非您强制进行 binary 比较,或者您在 db/table 上使用区分大小写的排序规则.

And by default, mysql comparisons ARE case insensitive, unless you force a binary comparison, or you're using a case sensitive collation on your db/table.