These days I’ve been working on a Symfony Upgrade (From version 5.2 to 6.4 LTS) and I’ve been dealing with deprecated code, some unnoticeable (does this word exist?) :D.
At one moment we needed to change some MySQL global settings but restarting the service wasn’t an option so we created an EventSubscriber to execute a query in our DB engine post connection.
<?php
namespace MyApp\MyBundle\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
class SetBlockEncryptionModeSubscriber implements EventSubscriber
{
public function getSubscribedEvents()
{
return [
Events::postConnect,
];
}
public function postConnect(ConnectionEventArgs $args)
{
$connection = $args->getConnection();
// Set the session variable for block encryption mode
$connection->executeStatement("SET SESSION block_encryption_mode = 'AES-128-CBC'");
}
}
This was working good but with the upgrades it stopped executing, DBAL events were deprecated. I debugged the class by dumping some variables without success, after trying with ChatGPT and Google searching (this one point it us in the right direction with their AI Overview).
The solution was to set our query in the config.yml or the dbal config yml.
doctrine:
dbal:
default_connection: default
connections:
default:
options:
1002: "SET SESSION block_encryption_mode = 'AES-128-CBC'"This worked perfectly.
If you want more information about the config, this is what I just search to get an screenshot of the solution. Hope this helps!


Leave a Reply