Correct way to install driverOptions to configure DBAL Doctrine in symfony2

I installed driverOptions in the configuration file, as indicated in the DBAL doctrine documentation.

But it gives an error

1/1 InvalidConfigurationException: unrecognized "driverOptions" options in the "doctrine.dbal.connections.pdoDevCon" section

My configuration file

dbal: default_connection: pdoDevCon connections: pdoDevCon: driver: %dev_database_driver% # < host: %dev_database_host% # | port: %dev_database_port% # | Defined in user: %dev_database_user% # | password: %dev_database_password% # < charset: UTF8 driverOptions: {3: 2} mapping_types: enum: string set: string orm: auto_generate_proxy_classes: %kernel.debug% pdoDevCon: connection: pdoDevCon mappings: AcmeDemoBundle: ~ AcmeHelloBundle: ~ 

I use PDO :: ATTR_ERRMODE as 3 PDO :: ERRMODE_EXCEPTION as 2 , it does not work even if I use strings.

+4
source share
2 answers

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

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

There are no driverOptions symfony yml configuration file, just options

+7
source

I do not use Symfony, but I used Doctrine\DBAL\DriverManager::getConnection() .

I had to take the DriverManager step and make this song and dance to indicate the 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 the pdo_mysql driver, this can be customized.

+3
source

Source: https://habr.com/ru/post/1346132/


All Articles