10000 [DoctrineBundle] Add infos about disabling the Autocommit mode by Crovitche-1623 · Pull Request #20824 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBundle] Add infos about disabling the Autocommit mode #20824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 7.2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Informations about disabling the autocommit mode
  • Loading branch information
Crovitche-1623 authored Mar 25, 2025
commit d75b53bed8bb9d748e53f01ee2afcaee0c0ced29
88 changes: 87 additions & 1 deletion reference/configuration/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,91 @@ you can access it using the ``getConnection()`` method and the name of the conne
}
}

Disabling the Autocommit mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want to disable the `Autocommit`_ mode, you need to update your DBAL configuration as follows:

.. configuration-block::

. 8000 . code-block:: yaml

doctrine:
dbal:
connections:
default:
options:
# Only if you're using DBAL with PDO:
!php/const PDO::ATTR_AUTOCOMMIT: false

# This line disables auto-commit at the DBAL level:
auto_commit: false

.. code-block:: xml
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd>
<doctrine:config>
<doctrine:dbal
auto-commit="false"
>
<!-- Only if you are using DBAL with PDO -->
<doctrine:option key-type="constant" key="PDO::ATTR_AUTOCOMMIT">false</doctrine:option>
</doctrine:dbal>
</doctrine:config>
</container>


If you are managing your database migrations using the `Doctrine Migrations Bundle`_, you must also register a listener to ensure that the last migration is properly commited:

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
services:
Doctrine\Migrations\Event\Listeners\AutoCommitListener:
tags:
- name: doctrine.event_listener
event: !php/const Doctrine\Migrations\Events::onMigrationsMigrated

.. code-block:: xml

<!-- config/services.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"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Doctrine\Migrations\Event\Listeners\AutoCommitListener">
<tag name="doctrine.event_listener" event="onMigrationsMigrated" />
</service>
</services>
</container>

.. code-block:: php

// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Doctrine\Migrations\Event\Listeners\AutoCommitListener;
use Doctrine\Migrations\Events;

return function(ContainerConfigurator $container): void {
$services = $container->services();

$services->set(AutoCommitListener::class)
->tag('doctrine.event_listener', [
'event' => Events::onMigrationsMigrated
])
;
};

Doctrine ORM Configuration
--------------------------

Expand Down Expand Up @@ -544,6 +629,7 @@ Ensure your environment variables are correctly set in the ``.env.local`` or

This configuration secures your MySQL connection with SSL by specifying the paths to the required certificates.


.. _Autocommit: https://en.wikipedia.org/wiki/Autocommit
.. _Doctrine Migrations Bundle: https://github.com/doctrine/DoctrineMigrationsBundle
.. _DBAL documentation: https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html
.. _`Doctrine Metadata Drivers`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/metadata-drivers.html
0