Doctrine2:如何设置所有表以使用 UTF8 进行整理 [英] Doctrine2: How to set all tables to collate with UTF8

查看:24
本文介绍了Doctrine2:如何设置所有表以使用 UTF8 进行整理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Symfony2 中使用 Doctrine.我的 config.yml 文件看起来像这样:-

I am using Doctrine with Symfony2. My config.yml file looks something like this:-

doctrine:
    dbal:
        driver: %database_driver%
        host: %database_host%
        port: %database_port%
        dbname: %database_name%
        user: %database_user%
        password: %database_password%
        charset: UTF8

不幸的是我的表没有整理到 UTF8_general_ci 或 UTF8_unicode_ci我试过

Unfortunately my tables are not collating to the UTF8_general_ci or UTF8_unicode_ci I tried

collate: utf8_unicode_ci

但是 Doctrine2 无法识别该选项.

But Doctrine2 didn't recognize the option.

我怎样才能达到同样的目的?

How can I achieve the same?

推荐答案

charset: UTF8 选项仅用于要求 Doctrine 在上执行 SET NAMES UTF-8每页.我没有任何特定的 Doctrine 配置,我的表默认在 utf8_general_ci InnoDB 中.阅读文档的这一部分:https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/faq.html#how-do-i-set-the-charset-and-collat​​ion-for-mysql-tables,它回答了你的问题:

The charset: UTF8 option is just useful to ask Doctrine to execute SET NAMES UTF-8 on each page. I don't have any specific configuration for Doctrine, and my tables are by default in utf8_general_ci InnoDB. Read this part of the documentation: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/faq.html#how-do-i-set-the-charset-and-collation-for-mysql-tables, it answers your question:

您不能在注解、yml 或 xml 映射中设置这些值文件.使数据库使用默认字符集和排序规则您应该配置 MySQL 以将其用作默认字符集,或创建具有字符集和排序规则详细信息的数据库.这样他们得到继承到所有新创建的数据库表和列.

You can’t set these values inside the annotations, yml or xml mapping files. To make a database work with the default charset and collation you should configure MySQL to use it as default charset, or create the database with charset and collation details. This way they get inherited to all newly created database tables and columns.

这篇关于Doctrine2:如何设置所有表以使用 UTF8 进行整理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆