. */ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; use Doctrine\Common\EventSubscriber; /** * Session init listener for executing a single SQL statement right after a connection is opened. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.com * @since 2.2 * @author Benjamin Eberlei */ class SQLSessionInit implements EventSubscriber { /** * @var string */ protected $sql; /** * @param string $sql */ public function __construct($sql) { $this->sql = $sql; } /** * @param ConnectionEventArgs $args * @return void */ public function postConnect(ConnectionEventArgs $args) { $conn = $args->getConnection(); $conn->exec($this->sql); } public function getSubscribedEvents() { return array(Events::postConnect); } }