在where子句中使用元音变换查询什么都不返回

时间:2018-04-16 14:21:09

标签: mysql symfony doctrine-orm

我想在我的Symfony应用程序中的where条件中使用德语变音符号过滤一个表,但奇怪的是它不起作用。

代码:

$queryBuilder = $this->entityManager
    ->createQueryBuilder()
    ->select('p')
    ->from('AppBundle:Tablename', 'p');
$queryBuilder->andWhere('p.firm like :searchTerm');
$parameters['searchTerm'] = '%'.$data['search'].'%';
$dql = $this->entityManager
    ->createQuery($queryBuilder->getDql())
    ->setParameters($parameters);

数据:

MySQL [mydb_de]> SELECT firm FROM tablename WHERE firm LIKE '%bar%';
+---------+
| firm    |
+---------+
| föo&bar |
+---------+
1 rows in set (0.01 sec)

MySQL [mydb_de]> SELECT firm FROM tablename WHERE firm LIKE '%föo%';
+---------+
| firm    |
+---------+
| föo&bar |
+---------+
1 row in set (0.01 sec)

我在搜索bar时收到了预期的结果,但搜索föo时没有结果。

db:

的其他信息
MySQL [mydb_de]> SHOW CREATE TABLE tablename;
+------------------+---------------------------------------+
| Table            | Create Table                          |
+------------------+---------------------------------------+
| tablename | CREATE TABLE `tablename` (
  `firm` varchar(100) DEFAULT NULL,
  ...
) ENGINE=MyISAM AUTO_INCREMENT=1902 DEFAULT CHARSET=latin1 |
+------------------+---------------------------------------+
1 row in set (0.00 sec)

MySQL [mydb_de]> SHOW TABLE STATUS where name like 'tablename';
+-----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+----------------+---------+
| Name      | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time          | Collation         | Checksum | Create_options | Comment |
+-----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+----------------+---------+
| tablename | MyISAM |      10 | Dynamic    | 1835 |             94 |      172556 | 281474976710655 |        33792 |         0 |           1902 | 2018-04-16 11:34:57 | 2018-04-16 11:34:57 | 2018-04-16 11:34:57 | latin1_swedish_ci |     NULL |                |         |
+-----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+----------------+---------+
1 row in set (0.00 sec)

MySQL [mydb_de]> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

我试图将config.yml(doctrine.dbal.charset)中的字符集切换为latin1latin1_swedish_ci而没有运气。

我启用了日志记录(doctrine.dbal.logging),在Profiler中找到了查询并检查了searchTerm,我觉得很好看:

query parameter in Profiler

我们有许多国家/地区的数据库,其中一些使用utf8,但其他国家/地区不使用。据我所知,我们的德国数据库不使用utf8,并且在不久的将来无法改变它

Symfony-Version:3.4.6
主义 - 版本:2.5.14
MySQL版本:5.5.47

有人知道可能导致这种情况的原因吗?

1 个答案:

答案 0 :(得分:2)

Symfony for Doctrine的默认配置如下:

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        url: '(your database url)'

此配置指定数据库表应使用interclassment utf8mb4。准确地使用特殊字符(如果你不使用mariadb,也可以使用复杂的utf-8字符(f.i.emojis))。