-->

Doctrine Dbal: How to set collation? (in Symfony2)

2020-07-24 04:47发布

问题:

I'm used to creating the PDO object with something like this in the 4th parameter (driver options):

array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES {$this->charset} COLLATE {$this->collation}")

How can I tell symfony 2 to do this? In the configuration file I can only see a 'charset' option.

I also need to create all the tables with a specific collation: utf8_unicode_ci

What can I do to have all the tables created through the command line be created with that collation instead of latin1?

回答1:

I have been facing the same problem. It seems that has to do with DBAL configuration. I have found in the PDO documentation the following under the PDO_MYSQL DSN — Connecting to MySQL databases:

charset Currently ignored.



回答2:

My solution was to apply the collation manually at the database level. Then all tables created in Symfony2 with the schema update command will have the correct collation.

I also added this line to my Sf2 doctrine: dbal configuration in the config.yml:

    charset: utf8