Documentation

DriverManager
in package

FinalYes

Factory for creating {@see Connection} instances.

Tags
psalm-type

OverrideParams = array{ application_name?: string, charset?: string, dbname?: string, default_dbname?: string, driver?: key-ofself::DRIVER_MAP, driverClass?: class-string<Driver>, driverOptions?: array, host?: string, password?: string, path?: string, persistent?: bool, platform?: Platforms\AbstractPlatform, port?: int, serverVersion?: string, url?: string, user?: string, unix_socket?: string, }

psalm-type

Params = array{ application_name?: string, charset?: string, dbname?: string, defaultTableOptions?: array<string, mixed>, default_dbname?: string, driver?: key-ofself::DRIVER_MAP, driverClass?: class-string<Driver>, driverOptions?: array, host?: string, keepSlave?: bool, keepReplica?: bool, master?: OverrideParams, memory?: bool, password?: string, path?: string, persistent?: bool, platform?: Platforms\AbstractPlatform, port?: int, primary?: OverrideParams, replica?: array<OverrideParams>, serverVersion?: string, sharding?: array<string,mixed>, slaves?: array<OverrideParams>, url?: string, user?: string, wrapperClass?: class-string<Connection>, unix_socket?: string, }

Table of Contents

Constants

DRIVER_MAP  = ['pdo_mysql' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class, 'pdo_sqlite' => \Doctrine\DBAL\Driver\PDO\SQLite\Driver::class, 'pdo_pgsql' => \Doctrine\DBAL\Driver\PDO\PgSQL\Driver::class, 'pdo_oci' => \Doctrine\DBAL\Driver\PDO\OCI\Driver::class, 'oci8' => \Doctrine\DBAL\Driver\OCI8\Driver::class, 'ibm_db2' => \Doctrine\DBAL\Driver\IBMDB2\Driver::class, 'pdo_sqlsrv' => \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver::class, 'mysqli' => \Doctrine\DBAL\Driver\Mysqli\Driver::class, 'pgsql' => \Doctrine\DBAL\Driver\PgSQL\Driver::class, 'sqlsrv' => \Doctrine\DBAL\Driver\SQLSrv\Driver::class, 'sqlite3' => \Doctrine\DBAL\Driver\SQLite3\Driver::class]
List of supported drivers and their mappings to the driver classes.

Properties

$driverSchemeAliases  : array<string|int, string>
List of URL schemes from a database URL and their mappings to driver.

Methods

getAvailableDrivers()  : array<string|int, string>
Returns the list of supported drivers.
getConnection()  : Connection
Creates a connection object based on the specified parameters.
__construct()  : mixed
Private constructor. This class cannot be instantiated.
createDriver()  : Driver
parseDatabaseUrl()  : array<string|int, mixed>
Extracts parts from a database URL, if present, and returns an updated list of parameters.

Constants

DRIVER_MAP

List of supported drivers and their mappings to the driver classes.

private mixed DRIVER_MAP = ['pdo_mysql' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class, 'pdo_sqlite' => \Doctrine\DBAL\Driver\PDO\SQLite\Driver::class, 'pdo_pgsql' => \Doctrine\DBAL\Driver\PDO\PgSQL\Driver::class, 'pdo_oci' => \Doctrine\DBAL\Driver\PDO\OCI\Driver::class, 'oci8' => \Doctrine\DBAL\Driver\OCI8\Driver::class, 'ibm_db2' => \Doctrine\DBAL\Driver\IBMDB2\Driver::class, 'pdo_sqlsrv' => \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver::class, 'mysqli' => \Doctrine\DBAL\Driver\Mysqli\Driver::class, 'pgsql' => \Doctrine\DBAL\Driver\PgSQL\Driver::class, 'sqlsrv' => \Doctrine\DBAL\Driver\SQLSrv\Driver::class, 'sqlite3' => \Doctrine\DBAL\Driver\SQLite3\Driver::class]

To add your own driver use the 'driverClass' parameter to DriverManager::getConnection().

Properties

$driverSchemeAliases

List of URL schemes from a database URL and their mappings to driver.

private static array<string|int, string> $driverSchemeAliases = [ 'db2' => 'ibm_db2', 'mssql' => 'pdo_sqlsrv', 'mysql' => 'pdo_mysql', 'mysql2' => 'pdo_mysql', // Amazon RDS, for some weird reason 'postgres' => 'pdo_pgsql', 'postgresql' => 'pdo_pgsql', 'pgsql' => 'pdo_pgsql', 'sqlite' => 'pdo_sqlite', 'sqlite3' => 'pdo_sqlite', ]
Tags
deprecated

Use actual driver names instead.

Methods

getAvailableDrivers()

Returns the list of supported drivers.

public static getAvailableDrivers() : array<string|int, string>
Tags
psalm-return

list<key-ofself::DRIVER_MAP>

Return values
array<string|int, string>

getConnection()

Creates a connection object based on the specified parameters.

public static getConnection(array<string|int, mixed> $params[, Configuration|null $config = null ][, EventManager|null $eventManager = null ]) : Connection

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 array keys of DRIVER_MAP, OR 'driverClass' that contains the full class name (with namespace) of the driver class to instantiate.

Other (optional) parameters:

user (string): The username to use when connecting.

password (string): The password to use when connecting.

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

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

driverClass: The driver class to use.

Parameters
$params : array<string|int, mixed>
$config : Configuration|null = null

The configuration to use.

$eventManager : EventManager|null = null

The event manager to use.

Tags
psalm-param

Params $params

psalm-return

($params is array{wrapperClass: class-string<T>} ? T : Connection)

throws
Exception
template

T of Connection

Return values
Connection

__construct()

Private constructor. This class cannot be instantiated.

private __construct() : mixed
Tags
codeCoverageIgnore

createDriver()

private static createDriver(string|null $driver, Driver>|null $driverClass) : Driver
Parameters
$driver : string|null
$driverClass : Driver>|null
Tags
throws
Exception
Return values
Driver

parseDatabaseUrl()

Extracts parts from a database URL, if present, and returns an updated list of parameters.

private static parseDatabaseUrl(array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

The list of parameters.

Tags
psalm-param

Params $params

psalm-return

Params

throws
Exception
Return values
array<string|int, mixed>

A modified list of parameters with info from a database URL extracted into indidivual parameter parts.


        
On this page

Search results