11. Events

Both Doctrine\DBAL\DriverManager and Doctrine\DBAL\Connection accept an instance of Doctrine\Common\EventManager. The EventManager has a couple of events inside the DBAL layer that are triggered for the user to listen to.

11.1. PostConnect Event

Doctrine\DBAL\Events::postConnect is triggered right after the connection to the database is established. It allows to specify any relevant connection specific options and gives access to the Doctrine\DBAL\Connection instance that is responsible for the connection management via an instance of Doctrine\DBAL\Event\ConnectionEventArgs event arguments instance.

Doctrine ships with one implementation for the “PostConnect” event:

  • Doctrine\DBAL\Event\Listeners\OracleSessionInit allows to specify any number of Oracle Session related enviroment variables that are set right after the connection is established.

You can register events by subscribing them to the EventManager instance passed to the Connection factory:

$evm = new EventManager();
$evm->addEventSubscriber(new OracleSessionInit(array(
    'NLS_TIME_FORMAT' => 'HH24:MI:SS',

$conn = DriverManager::getConnection($connectionParams, null, $evm);

Project Versions

Table Of Contents

Previous topic

10. Schema-Representation

Next topic

12. Security

This Page

Fork me on GitHub