php - MySQL - 搜索瑞典语字符

标签 php mysql cakephp unicode

我已将瑞典语单词存储在 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/

相关文章:

PHP 页面显示在 ubuntu 上,而不是在 Windows 7 上

javascript - 使用旧的 jQuery 和在新的 jQuery 上制作的脚本

php - Vagrant 服务器没有出现?

php - Doctrine 2 查找具有属性的页面

cakephp - php cake inflection.php - 为什么 "cookie"在未变形单词列表中?

forms - CAKEPHP 确认提交

PHP preg_replace 的连续次数取决于匹配项?

java - 如何打印从 SQL 到 Java 到 CSV 的列部分?

mysql - 更新自定义帖子类型元值的 WordPress SQL(超过 6 个月)

cakephp - 使用带有 cakephp 2.0 的第三方库