Correct way to set the driverOptions for Doctrine DBAL configuration in symfony2

懵懂的女人 提交于 2019-12-04 10:41:46

From http://symfony.com/doc/master/reference/configuration/doctrine.html#doctrine-dbal-configuration

DoctrineBundle supports all parameters that default Doctrine drivers accept, converted to the XML or YAML naming standards that Symfony enforces. See the Doctrine DBAL documentation for more information.

There is no driverOptions in symfony yml configuration file, just options

I'm not using Symfony but I was using Doctrine\DBAL\DriverManager::getConnection().

I had to side step the DriverManager and do this song and dance to specify a connection timeout (ATTR_TIMEOUT):

function buildDbConn($config, $timeout) {
    $params = $config->toArray();
    $params['driverOptions'] = [
        PDO::ATTR_TIMEOUT => intval($timeout),
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ];
    $driver = new Doctrine\DBAL\Driver\PDOMySql\Driver;
    return new Doctrine\DBAL\Connection($params, $driver);
}

I always need a pdo_mysql driver, this could be configurable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!