Skip to content

Commit

Permalink
feature #6274 Update Doctrine UTF8 docs (mcfedr)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.0 branch.

Discussion
----------

Update Doctrine UTF8 docs

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

Commits
-------

dcd1126 Update Doctrine UTF8 docs
  • Loading branch information
weaverryan committed Mar 17, 2016
2 parents f24b8f8 + dcd1126 commit 24c2404
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 24c2404

Please sign in to comment.