我有一个这样的查询:
$profilesx->where('qZipCode', $location)->
orWhere('qCity', 'LIKE', '%'.$location.'%');
位置等于贝尔格莱德
,数据库列显示贝尔格莱德
。
它似乎区分大小写(使用 = 或 LIKE),因此如果我搜索 Belgrade
我会得到结果,但如果我搜索 belgrade
我不会得到结果任何结果。
如何使其不区分大小写?
最佳答案
The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:
来源:http://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html
实际发生的情况是区分大小写已被关闭(这不一定是坏事)。该文档的下一部分给出了解决方案。尝试类似的事情
orWhere('qCity', 'COLLATE latin1_general_cs LIKE', '%'.$location.'%');
如果 laravel 不喜欢它,您将不得不使用原始查询或更改列的排序规则设置。
顺便说一句,如果可以的话,请尽量避免 LIKE %something% 查询。 Mysql 无法对此类查询使用索引,因此它们在大型表上通常会很慢。
关于php - ->where() 子句似乎区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38523383/