Skip to content

Commit dba5234

Browse files
committed
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
1 parent 4924513 commit dba5234

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

Diff for: book/doctrine.rst

+48-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ for you:
131131
$ php bin/console doctrine:database:drop --force
132132
$ php bin/console doctrine:database:create
133133
134-
There's no way to configure these defaults inside Doctrine, as it tries to be
135-
as agnostic as possible in terms of environment configuration. One way to solve
136-
this problem is to configure server-level defaults.
137-
138134
Setting UTF8 defaults for MySQL is as simple as adding a few lines to
139135
your configuration file (typically ``my.cnf``):
140136

@@ -145,6 +141,54 @@ for you:
145141
collation-server = utf8mb4_general_ci # Replaces utf8_general_ci
146142
character-set-server = utf8mb4 # Replaces utf8
147143
144+
You can also change the defaults for Doctrine so that the generated SQL
145+
uses the correct character set.
146+
147+
.. configuration-block::
148+
149+
.. code-block:: yaml
150+
151+
doctrine:
152+
charset: utf8mb4
153+
dbal:
154+
default_table_options:
155+
charset: utf8mb4
156+
collate: utf8mb4_unicode_ci
157+
158+
.. code-block:: xml
159+
160+
<!-- app/config/config.xml -->
161+
<?xml version="1.0" encoding="UTF-8" ?>
162+
<container xmlns="http://symfony.com/schema/dic/services"
163+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
164+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
165+
xsi:schemaLocation="http://symfony.com/schema/dic/services
166+
http://symfony.com/schema/dic/services/services-1.0.xsd
167+
http://symfony.com/schema/dic/doctrine
168+
http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
169+
170+
<doctrine:config>
171+
<doctrine:dbal
172+
charset="utf8mb4">
173+
<doctrine:default-table-option name="charset">utf8mb4</doctrine:default-table-option>
174+
<doctrine:default-table-option name="collate">utf8mb4_unicode_ci</doctrine:default-table-option>
175+
</doctrine:dbal>
176+
</doctrine:config>
177+
</container>
178+
179+
.. code-block:: php
180+
181+
// app/config/config.php
182+
$configuration->loadFromExtension('doctrine', array(
183+
'dbal' => array(
184+
'charset' => 'utf8mb',
185+
'default_table_options' => array(
186+
'charset' => 'utf8mb4'
187+
'collate' => 'utf8mb4_unicode_ci'
188+
)
189+
),
190+
));
191+
148192
We recommend against MySQL's ``utf8`` character set, since it does not
149193
support 4-byte unicode characters, and strings containing them will be
150194
truncated. This is fixed by the `newer utf8mb4 character set`_.

0 commit comments

Comments
 (0)