@@ -221,6 +221,96 @@ you can access it using the ``getConnection()`` method and the name of the conne
221221 }
222222 }
223223
224+ Disable Autocommit Mode
225+ ~~~~~~~~~~~~~~~~~~~~~~~
226+
227+ To disable the `Autocommit `_ mode, update your DBAL configuration as follows:
228+
229+ .. configuration-block ::
230+
231+ .. code-block :: yaml
232+
233+ doctrine :
234+ dbal :
235+ connections :
236+ default :
237+ options :
238+ # Only if you're using DBAL with PDO:
239+ !php/const PDO::ATTR_AUTOCOMMIT: false
240+
241+ # This line disables auto-commit at the DBAL level:
242+ auto_commit : false
243+
244+ .. code-block :: xml
245+
246+ <?xml version =" 1.0" encoding =" UTF-8" ?>
247+ <container xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
248+ xmlns : doctrine =" http://symfony.com/schema/dic/doctrine"
249+ xmlns =" http://symfony.com/schema/dic/services"
250+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
251+ https://symfony.com/schema/dic/services/services-1.0.xsd
252+ http://symfony.com/schema/dic/doctrine
253+ https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" >
254+
255+ <doctrine : config >
256+ <doctrine : dbal
257+ auto-commit =" false"
258+ >
259+ <!-- Only if you are using DBAL with PDO -->
260+ <doctrine : connection name =" default" >
261+ <doctrine : option key-type =" constant" key =" PDO::ATTR_AUTOCOMMIT" >false</doctrine : option >
262+ </doctrine : connection >
263+ </doctrine : dbal >
264+ </doctrine : config >
265+ </container >
266+
267+ When using the `Doctrine Migrations Bundle `_, an additional listener needs to be registered to ensure that the last migration is properly committed:
268+
269+ .. configuration-block ::
270+
271+ .. code-block :: yaml
272+
273+ # config/services.yaml
274+ services :
275+ Doctrine\Migrations\Event\Listeners\AutoCommitListener :
276+ tags :
277+ - name : doctrine.event_listener
278+ event : onMigrationsMigrated
279+
280+ .. code-block :: xml
281+
282+ <!-- config/services.xml -->
283+ <?xml version =" 1.0" encoding =" UTF-8" ?>
284+ <container xmlns =" http://symfony.com/schema/dic/services"
285+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
286+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
287+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
288+
289+ <services >
290+ <service id =" Doctrine\Migrations\Event\Listeners\AutoCommitListener" >
291+ <tag name =" doctrine.event_listener" event =" onMigrationsMigrated" />
292+ </service >
293+ </services >
294+ </container >
295+
296+ .. code-block :: php
297+
298+ // config/services.php
299+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
300+
301+ use Doctrine\Migrations\Event\Listeners\AutoCommitListener;
302+ use Doctrine\Migrations\Events;
303+
304+ return function(ContainerConfigurator $container): void {
305+ $services = $container->services();
306+
307+ $services->set(AutoCommitListener::class)
308+ ->tag('doctrine.event_listener', [
309+ 'event' => Events::onMigrationsMigrated
310+ ])
311+ ;
312+ };
313+
224314 Doctrine ORM Configuration
225315--------------------------
226316
@@ -663,6 +753,7 @@ Ensure your environment variables are correctly set in the ``.env.local`` or
663753
664754 This configuration secures your MySQL connection with SSL by specifying the paths to the required certificates.
665755
666-
756+ .. _Autocommit : https://en.wikipedia.org/wiki/Autocommit
757+ .. _Doctrine Migrations Bundle : https://github.com/doctrine/DoctrineMigrationsBundle
667758.. _DBAL documentation : https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html
668759.. _`Doctrine Metadata Drivers` : https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/metadata-drivers.html
0 commit comments