DriverManager
in package
Factory for creating {@see Connection} instances.
Tags
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
Methods
getAvailableDrivers()
Returns the list of supported drivers.
public
static getAvailableDrivers() : array<string|int, string>
Tags
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
Return values
Connection__construct()
Private constructor. This class cannot be instantiated.
private
__construct() : mixed
Tags
createDriver()
private
static createDriver(string|null $driver, Driver>|null $driverClass) : Driver
Parameters
- $driver : string|null
- $driverClass : Driver>|null
Tags
Return values
DriverparseDatabaseUrl()
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
Return values
array<string|int, mixed> —A modified list of parameters with info from a database URL extracted into indidivual parameter parts.