Doctrine2:如何将所有表设置为与UTF8整理 [英] Doctrine2: How to set all tables to collate with UTF8

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

问题描述

我正在使用教条与Symfony2。
我的config.yml文件看起来像这样: -



教义配置



  doctrine:
dbal:
驱动程序:%database_driver%
主机:%database_host%
端口:%database_port%
dbname:%database_name%
用户:%database_user%
密码:%database_password%
charset:UTF8

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

  collat​​e:utf8_unicode_ci 

但是Doctrine2无法识别该选项。



如何实现相同?

解决方案

charset:UTF8 选项仅用于在每个页面上询问Doctrine执行 SET NAMES UTF-8 。我没有任何具体的Doctrine配置,我的表默认在utf8_general_ci InnoDB中。
阅读这部分文件: http://www.doctrine-project.org/docs/orm/2.1/en/reference/faq.html#how-do- i-set-the-charset-and-collat​​ion-for-mysql-tables ,它回答了你的问题:


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



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

Doctrine Configuration

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

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

collate: utf8_unicode_ci

But Doctrine2 didn't recognize the option.

How can I achieve the same?

解决方案

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: http://www.doctrine-project.org/docs/orm/2.1/en/reference/faq.html#how-do-i-set-the-charset-and-collation-for-mysql-tables, it answers your question:

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天全站免登陆