我已将瑞典语单词存储在 MySQL 数据库中。表的编码是
utf8_unicode_ci
我也尝试过
utf8_swedish_ci
当我在数据库中进行搜索时,“a”和“ä”被视为相同。因此结果包括以 a 和 ä 开头的两个单词。反之亦然。 我的应用程序是用 CakePHP 开发的,我的 core.php 中有以下内容
Configure::write('App.encoding', 'UTF-8');
我在这里遗漏了什么吗?
这是我的查询:
$term = $this->request->query['term'];
$this->loadModel('Words');
$condition = array('word LIKE' => trim($term) . '%', 'is_active' => true);
$words = $this->Words->find('list', array(
'fields' => array('word'),
'limit' => 7,
'conditions' => $condition));
return $this->respond($words, true);
我使用 Jquery 自动完成:
$(function () {
$("#tags").autocomplete({
source: 'autocomplete'
});
});
最佳答案
$query_result = $this->Words->query("SELECT word FROM tbl_words WHERE word LIKE '" . $term . "%' COLLATE utf8_bin LIMIT 7 ;");
这对我来说非常有用。感谢@Mihai 的评论。
关于php - MySQL - 搜索瑞典语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27030081/