where子句中带有umlauts的查询不返回任何内容

ulydmbyx  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(271)

我想在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 )至 latin1 以及 latin1_swedish_ci 没有运气。
我启用了日志记录( doctrine.dbal.logging ),在探查器中找到查询并检查搜索词,看起来不错,我猜:

我们有许多国家的数据库,其中一些使用utf8,但其他国家没有。我们的德国db不使用utf8据我所知,这是不可能改变在不久的将来
symfony版本:3.4.6
条令版本:2.5.14
mysql版本:5.5.47
有人知道是什么引起的吗?

yqkkidmi

yqkkidmi1#

条令symfony的默认配置如下:

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

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

相关问题