Skip to content

Commit 24c2404

Browse files
committed
feature symfony#6274 Update Doctrine UTF8 docs (mcfedr)
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
2 parents f24b8f8 + dcd1126 commit 24c2404

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

book/doctrine.rst

+49-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,55 @@ 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+
# app/config/config.yml
152+
doctrine:
153+
charset: utf8mb4
154+
dbal:
155+
default_table_options:
156+
charset: utf8mb4
157+
collate: utf8mb4_unicode_ci
158+
159+
.. code-block:: xml
160+
161+
<!-- app/config/config.xml -->
162+
<?xml version="1.0" encoding="UTF-8" ?>
163+
<container xmlns="http://symfony.com/schema/dic/services"
164+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
165+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
166+
xsi:schemaLocation="http://symfony.com/schema/dic/services
167+
http://symfony.com/schema/dic/services/services-1.0.xsd
168+
http://symfony.com/schema/dic/doctrine
169+
http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
170+
171+
<doctrine:config>
172+
<doctrine:dbal
173+
charset="utf8mb4">
174+
<doctrine:default-table-option name="charset">utf8mb4</doctrine:default-table-option>
175+
<doctrine:default-table-option name="collate">utf8mb4_unicode_ci</doctrine:default-table-option>
176+
</doctrine:dbal>
177+
</doctrine:config>
178+
</container>
179+
180+
.. code-block:: php
181+
182+
// app/config/config.php
183+
$configuration->loadFromExtension('doctrine', array(
184+
'dbal' => array(
185+
'charset' => 'utf8mb4',
186+
'default_table_options' => array(
187+
'charset' => 'utf8mb4'
188+
'collate' => 'utf8mb4_unicode_ci'
189+
)
190+
),
191+
));
192+
148193
We recommend against MySQL's ``utf8`` character set, since it does not
149194
support 4-byte unicode characters, and strings containing them will be
150195
truncated. This is fixed by the `newer utf8mb4 character set`_.

0 commit comments

Comments
 (0)