问题描述
我有一个MySQL数据库,其中包含西班牙语(áéíóú)中的重音符号。我想知道是否有任何方式做一个变音敏感搜索。例如,如果我搜索lapiz(无口音),我想得到包含单词lápiz从我的数据库的结果。我目前正在做的查询的方式如下:
I have a MySQL database with words containing accents in Spanish (áéíóú). I'd like to know if there's any way to do a diacritic insensitive search. For instance, if I search for "lapiz" (without accent), i'd like to get results containing the word "lápiz" from my db. The way I'm currently doing the query is as follows:
$result = mysql_query("SELECT * FROM $lookuptable WHERE disabled = '0' AND name LIKE '%$q%' OR productCode LIKE '%$q%' LIMIT $sugglimit");
这是一个网上商店,所以我不知道人们会搜索什么。 。lapiz只是例子。
This is for an online store, so I don't know what people will be searching for... "lapiz" is just and example.
谢谢!
推荐答案
整理而不是我的最爱,但他们的工作:
Character sets & collations, not my favorites, but they DO work:
mysql> SET NAMES latin1;
mysql> SELECT 'lápiz' LIKE 'lapiz';
+-----------------------+
| 'lápiz' LIKE 'lapiz' |
+-----------------------+
| 0 |
+-----------------------+
1 row in set (0.01 sec)
mysql> SET NAMES utf8;
mysql> SELECT 'lápiz' LIKE 'lapiz';
+-----------------------+
| 'lápiz' LIKE 'lapiz' |
+-----------------------+
| 1 |
+-----------------------+
mysql> SET NAMES latin1;
mysql> SELECT _utf8'lápiz' LIKE _utf8'lapiz' ;
+---------------------------------+
| _utf8'lápiz' LIKE _utf8'lapiz' |
+---------------------------------+
| 1 |
+---------------------------------+
在本手册中阅读的一个好章节:
A nice chapter to read in the manual:Character Set Support
这篇关于MySQL变音符号不敏感搜索(西班牙语口音)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!