Skip to content

Commit

Permalink
Update Doctrine UTF8 docs
Browse files Browse the repository at this point in the history
Since its now possible (doctrine/DoctrineBundle#420) to set the default character set for all tables using DoctrineBundle it can be mentioned in the docs
  • Loading branch information
mcfedr committed Mar 8, 2016
1 parent 4924513 commit dcd1126
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions book/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``):

Expand All @@ -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
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine
http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
<doctrine:config>
<doctrine:dbal
charset="utf8mb4">
<doctrine:default-table-option name="charset">utf8mb4</doctrine:default-table-option>
<doctrine:default-table-option name="collate">utf8mb4_unicode_ci</doctrine:default-table-option>
</doctrine:dbal>
</doctrine:config>
</container>
.. 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`_.
Expand Down

0 comments on commit dcd1126

Please sign in to comment.