简体   繁体   English

Mysql搜索案例不敏感

[英]Mysql search case insensitive

I'm having problems searching in multiple tables for different values. 我在多个表中搜索不同的值时遇到问题。 When I search for "paul" I get nothing, but if I search for "Paul" I get the corresponding persons for orders with the name Paul. 当我搜索“保罗”时,我什么都没得到,但是如果我搜索“保罗”,我就会得到相应的人名为保罗。

$get_orders = mysql_query("
SELECT
  co.id, co.final_id, co.shop_id, co.customer_id, co.payment_type, co.payment_currency, co.billing_email, co.billing_first_name, co.billing_last_name, co.delivery_first_name, co.delivery_last_name, UNIX_TIMESTAMP(co.order_created) AS order_created, c.email, s.site_name, 
MATCH(co.final_id, co.billing_first_name, co.billing_last_name, co.delivery_first_name, co.delivery_last_name, co.order_created) 
AGAINST ('$match_against' IN BOOLEAN MODE) AS score 
FROM customer_orders AS co 
LEFT JOIN customers AS c ON c.id = co.customer_id 
LEFT JOIN shops AS s ON s.id = co.shop_id WHERE co.status = '{$os}' 
ORDER BY score DESC 
LIMIT $offset,$views_page") or die(mysql_error());

I've search all over for a solution to this problem. 我一直在寻找解决这个问题的方法。 I've tried using UPPER, changing the database collation from utf8_general_ci to utf8_bin (binary) but my problem still remains unsolved.. 我尝试过使用UPPER,将数据库排序从utf8_general_ci更改为utf8_bin(二进制),但我的问题仍然没有解决。

All suggestions are appreciated.. 所有建议都表示赞赏..

Regards 问候

See http://bugs.mysql.com/bug.php?id=22343 请参见http://bugs.mysql.com/bug.php?id=22343

From my understanding, make sure everything is a string if you want to search for a string. 根据我的理解,如果你想搜索字符串,请确保所有内容都是字符串。

Also, switch charset back to case-insensitive. 此外,将charset切换回不区分大小写。 No need for it to be binary. 不需要它是二进制的。

from the mysql manual: 来自mysql手册:

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. 默认字符集和排序规则是latin1和latin1_swedish_ci,因此非二进制字符串比较默认情况下不区分大小写。 This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. 这意味着如果使用col_name LIKE'a%'进行搜索,则会获得以A或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: 例如,如果要比较具有latin1字符集的列和字符串,则可以使用COLLATE运算符使任一操作数具有latin1_general_cs或latin1_bin排序规则:

see: mysql case sensitivity 看: mysql区分大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM