From dcd112639d60104abcf0abe5a6064e34ad997a4c Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Mon, 15 Feb 2016 11:23:34 +0200 Subject: [PATCH] Update Doctrine UTF8 docs Since its now possible (https://github.com/doctrine/DoctrineBundle/pull/420) to set the default character set for all tables using DoctrineBundle it can be mentioned in the docs --- book/doctrine.rst | 53 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 24248043376..4a47d7b5d0b 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -131,10 +131,6 @@ for you: $ php bin/console doctrine:database:drop --force $ php bin/console doctrine:database:create - There's no way to configure these defaults inside Doctrine, as it tries to be - as agnostic as possible in terms of environment configuration. One way to solve - this problem is to configure server-level defaults. - Setting UTF8 defaults for MySQL is as simple as adding a few lines to your configuration file (typically ``my.cnf``): @@ -145,6 +141,55 @@ for you: collation-server = utf8mb4_general_ci # Replaces utf8_general_ci character-set-server = utf8mb4 # Replaces utf8 + You can also change the defaults for Doctrine so that the generated SQL + uses the correct character set. + + .. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + doctrine: + charset: utf8mb4 + dbal: + default_table_options: + charset: utf8mb4 + collate: utf8mb4_unicode_ci + + .. code-block:: xml + + + + + + + + utf8mb4 + utf8mb4_unicode_ci + + + + + .. code-block:: php + + // app/config/config.php + $configuration->loadFromExtension('doctrine', array( + 'dbal' => array( + 'charset' => 'utf8mb4', + 'default_table_options' => array( + 'charset' => 'utf8mb4' + 'collate' => 'utf8mb4_unicode_ci' + ) + ), + )); + We recommend against MySQL's ``utf8`` character set, since it does not support 4-byte unicode characters, and strings containing them will be truncated. This is fixed by the `newer utf8mb4 character set`_.