Skip to content

DoctrineDbalDatabase

Tier-2 adapter: a Doctrine DBAL connection (connection abstraction + query builder) without the ORM/entity layer.

DoctrineDbalDatabase::getConnection() returns the Connection.

Parameters: either an inline connection array, a DSN url, or flat driver/host/dbname/user/password params (see DoctrineDbalParams).

class DoctrineDbalDatabase extends AbstractOrmDatabase

ExtendsAbstractOrmDatabase
UsesDoctrineDbalParams
SourceDoctrineDbalDatabase.php
MethodDescription
getDbalConnection(): ConnectionReturns the DBAL connection, connecting on first use.
getPdo(): PDOOnly available when the configured driver is a pdo_* one (pdo_mysql, pdo_pgsql, pdo_sqlite, …) — DBAL 4 also supports native drivers (mysqli, pgsql) that never construct a \PDO instance at all.
getQueryBuilder(): QueryBuilderReturns a fresh DBAL query builder bound to this connection.
ping(): boolProbes the connection with SELECT 1.
shutdown(): mixedRolls back any open transaction, closes the connection and drops it.

public function getDbalConnection(): Connection

Returns the DBAL connection, connecting on first use.

Returns Connection

ThrowsWhen
DatabaseExceptionIf the connection could not be created, or what was created is not a DBAL Connection.

public function getPdo(): PDO

Only available when the configured driver is a pdo_* one (pdo_mysql, pdo_pgsql, pdo_sqlite, …) — DBAL 4 also supports native drivers (mysqli, pgsql) that never construct a \PDO instance at all.

Returns PDO

public function getQueryBuilder(): QueryBuilder

Returns a fresh DBAL query builder bound to this connection.

A new builder is created on every call, so callers never share state.

Returns QueryBuilder

ThrowsWhen
DatabaseExceptionIf the connection could not be created.

public function ping(): bool

Probes the connection with SELECT 1.

Returns true when nothing has been connected yet, since lazy connect handles it on first use. If the query throws, the connection and resource are cleared so the next getConnection() reconnects, and false is returned.

Returns bool

public function shutdown(): mixed

Rolls back any open transaction, closes the connection and drops it.

A failure to roll back or close is logged at warning and does not stop the shutdown; the connection and resource are cleared either way.

Returns mixed

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getConnection()DatabaseRetrieve the database connection associated with this Database implementation.
getDatabaseManager()DatabaseRetrieve the Database Manager instance for this implementation.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getName()DatabaseRetrieve the name of this database connection.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
getResource()DatabaseRetrieve a raw database resource associated with this Database implementation.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()DatabaseInitialize this Database.
removeParameter()ParameterHolderRemove a parameter.
reset()DatabaseReturns this Database to its pre-initialize() state.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
startup()DatabaseDo any necessary startup work after initialization.