lib/Doctrine/DBAL/DriverManager.php
public static function getConnection(
        array $params,
        ?Configuration $config = null,
        ?EventManager $eventManager = null
    ) : Connection {
        // create default config and event manager, if not set
        if (! $config) {
            $config = new Configuration();
        }
        if (! $eventManager) {
            $eventManager = new EventManager();
        }

        $params = self::parseDatabaseUrl($params);

        // URL support for MasterSlaveConnection
        if (isset($params['master'])) {
            $params['master'] = self::parseDatabaseUrl($params['master']);
        }

        if (isset($params['slaves'])) {
            foreach ($params['slaves'] as $key => $slaveParams) {
                $params['slaves'][$key] = self::parseDatabaseUrl($slaveParams);
            }
        }

        // URL support for PoolingShardConnection
        if (isset($params['global'])) {
            $params['global'] = self::parseDatabaseUrl($params['global']);
        }

        if (isset($params['shards'])) {
            foreach ($params['shards'] as $key => $shardParams) {
                $params['shards'][$key] = self::parseDatabaseUrl($shardParams);
            }
        }

        // check for existing pdo object
        if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
            throw DBALException::invalidPdoInstance();
        }

        if (isset($params['pdo'])) {
            $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
        } else {
            self::_checkParams($params);
        }

        $className = $params['driverClass'] ?? self::$_driverMap[$params['driver']];

        $driver = new $className();

        $wrapperClass = Connection::class;
        if (isset($params['wrapperClass'])) {
            if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
                throw DBALException::invalidWrapperClass($params['wrapperClass']);
            }

            $wrapperClass = $params['wrapperClass'];
        }

        return new $wrapperClass($params, $driver, $config, $eventManager);
    }
public static function getConnection(
        array $params,
        ?Configuration $config = null,
        ?EventManager $eventManager = null
    ) : Connection {
        // create default config and event manager, if not set
        if (! $config) {
            $config = new Configuration();
        }
        if (! $eventManager) {
            $eventManager = new EventManager();
        }

        $params = self::parseDatabaseUrl($params);

        // URL support for MasterSlaveConnection
        if (isset($params['master'])) {
            $params['master'] = self::parseDatabaseUrl($params['master']);
        }

        if (isset($params['slaves'])) {
            foreach ($params['slaves'] as $key => $slaveParams) {
                $params['slaves'][$key] = self::parseDatabaseUrl($slaveParams);
            }
        }

        // URL support for PoolingShardConnection
        if (isset($params['global'])) {
            $params['global'] = self::parseDatabaseUrl($params['global']);
        }

        if (isset($params['shards'])) {
            foreach ($params['shards'] as $key => $shardParams) {
                $params['shards'][$key] = self::parseDatabaseUrl($shardParams);
            }
        }

        // check for existing pdo object
        if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
            throw DBALException::invalidPdoInstance();
        }

        if (isset($params['pdo'])) {
            $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
        } else {
            self::_checkParams($params);
        }

        $className = $params['driverClass'] ?? self::$_driverMap[$params['driver']];

        $driver = new $className();

        $wrapperClass = Connection::class;
        if (isset($params['wrapperClass'])) {
            if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
                throw DBALException::invalidWrapperClass($params['wrapperClass']);
            }

            $wrapperClass = $params['wrapperClass'];
        }

        return new $wrapperClass($params, $driver, $config, $eventManager);
    }
public static function getConnection ( array $ params , ? Configuration $ config = null , ? EventManager $ eventManager = null ) : Connection { // create default config and event manager, if not set if ( ! $ config ) { $ config = new Configuration ( ) ; } if ( ! $ eventManager ) { $ eventManager = new EventManager ( ) ; } $ params = self :: parseDatabaseUrl ( $ params ) ; // URL support for MasterSlaveConnection if ( isset ( $ params [ 'master' ] ) ) { $ params [ 'master' ] = self :: parseDatabaseUrl ( $ params [ 'master' ] ) ; } if ( isset ( $ params [ 'slaves' ] ) ) { foreach ( $ params [ 'slaves' ] as $ key => $ slaveParams ) { $ params [ 'slaves' ] [ $ key ] = self :: parseDatabaseUrl ( $ slaveParams ) ; } } // URL support for PoolingShardConnection if ( isset ( $ params [ 'global' ] ) ) { $ params [ 'global' ] = self :: parseDatabaseUrl ( $ params [ 'global' ] ) ; } if ( isset ( $ params [ 'shards' ] ) ) { foreach ( $ params [ 'shards' ] as $ key => $ shardParams ) { $ params [ 'shards' ] [ $ key ] = self :: parseDatabaseUrl ( $ shardParams ) ; } } // check for existing pdo object if ( isset ( $ params [ 'pdo' ] ) && ! $ params [ 'pdo' ] instanceof PDO ) { throw DBALException :: invalidPdoInstance ( ) ; } if ( isset ( $ params [ 'pdo' ] ) ) { $ params [ 'pdo' ] -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; $ params [ 'driver' ] = 'pdo_' . $ params [ 'pdo' ] -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ; } else { self :: _checkParams ( $ params ) ; } $ className = $ params [ 'driverClass' ] ?? self :: $ _driverMap [ $ params [ 'driver' ] ] ; $ driver = new $ className ( ) ; $ wrapperClass = Connection :: class ; if ( isset ( $ params [ 'wrapperClass' ] ) ) { if ( ! is_subclass_of ( $ params [ 'wrapperClass' ] , $ wrapperClass ) ) { throw DBALException :: invalidWrapperClass ( $ params [ 'wrapperClass' ] ) ; } $ wrapperClass = $ params [ 'wrapperClass' ] ; } return new $ wrapperClass ( $ params , $ driver , $ config , $ eventManager ) ; }
Creates a connection object based on the specified parameters.
This method returns a Doctrine\DBAL\Connection which wraps the underlying
driver connection.

$params must contain at least one of the following.

Either 'driver' with one of the following values:

pdo_mysql
pdo_sqlite
pdo_pgsql
pdo_oci (unstable)
pdo_sqlsrv
pdo_sqlsrv
mysqli
sqlanywhere
sqlsrv
ibm_db2 (unstable)
drizzle_pdo_mysql

OR 'driverClass' that contains the full class name (with namespace) of the
driver class to instantiate.

Other (optional) parameters:

<b>user (string)</b>:
The username to use when connecting.

<b>password (string)</b>:
The password to use when connecting.

<b>driverOptions (array)</b>:
Any additional driver-specific options for the driver. These are just passed
through to the driver.

<b>pdo</b>:
You can pass an existing PDO instance through this parameter. The PDO
instance will be wrapped in a Doctrine\DBAL\Connection.

<b>wrapperClass</b>:
You may specify a custom wrapper class through the 'wrapperClass'
parameter but this class MUST inherit from Doctrine\DBAL\Connection.

<b>driverClass</b>:
The driver class to use.

@param mixed[]            $params       The parameters.
@param Configuration|null $config       The configuration to use.
@param EventManager|null  $eventManager The event manager to use.

@throws DBALException
Creates a connection object based on the specified parameters . This method returns a Doctrine \ DBAL \ Connection which wraps the underlying driver connection .