Skip to content

DoctrineDatabase

Modern first-class adapter for Doctrine ORM 3 / DBAL 4.

DoctrineDatabase::getConnection() returns the EntityManagerInterface. Supersedes the legacy in-tree Doctrine2* adapters.

Configuration parameters (in databases.xml): - connection : the name (string) of a configured DoctrineDbalDatabase to reuse, OR an inline DBAL params array. Omit to build from flat params (see DoctrineDbalParams). NB: DBAL 4 cannot wrap a raw PDO, so referencing a plain PdoDatabase is not supported — reference a DoctrineDbalDatabase. - entity_paths : array of directories/files holding mapping metadata - metadata : “attribute” (default) | “xml” - dev_mode : bool (default = core.debug) — proxy auto-generation etc. - proxy_dir : directory for generated proxies (default: system temp) - proxy_namespace : namespace for generated proxy classes

Cache bridging (metadata/query caches to Quiote’s PSR-6 pool) is a follow-up; for now ORMSetup’s in-memory default is used unless a subclass overrides DoctrineDatabase::metadataCache().

class DoctrineDatabase extends AbstractOrmDatabase

ExtendsAbstractOrmDatabase
UsesDoctrineDbalParams
SourceDoctrineDatabase.php
MethodDescription
getDbalConnection(): ConnectionReturns the DBAL connection the entity manager runs on.
getEntityManager(): EntityManagerInterfaceReturns the Doctrine entity manager, 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.
getRepository(class-string<T> $entity): EntityRepository<T>
ping(): boolProbes the connection with SELECT 1 over DBAL.
reset(): voidReturns this database to its pre-initialize() state, detaching every managed entity first.
shutdown(): mixedRolls back any open transaction, closes the DBAL connection and drops the entity manager.

public function getDbalConnection(): Connection

Returns the DBAL connection the entity manager runs on.

This is the entry point for custom SQL — executeQuery() / executeStatement() — on drivers that never expose a PDO handle.

Returns Connection

ThrowsWhen
DatabaseExceptionIf the entity manager could not be built.

public function getEntityManager(): EntityManagerInterface

Returns the Doctrine entity manager, connecting on first use.

Returns EntityManagerInterface

ThrowsWhen
DatabaseExceptionIf the entity manager could not be built, or the connection is not an EntityManagerInterface.

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 getRepository(class-string<T> $entity): EntityRepository<T>

ParameterTypeDescription
$entityclass-string``<``T``>

Returns EntityRepository``<``T``>

public function ping(): bool

Probes the connection with SELECT 1 over DBAL.

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

Returns bool

public function reset(): void

Returns this database to its pre-initialize() state, detaching every managed entity first.

The identity map is cleared up front so entities are detached even for a caller still holding the entity manager; the base teardown then shuts the connection down and clears the parameters, the manager reference and the name. Re-initialize() this instance before using it again.

To recycle a worker’s connection between requests without discarding the configuration, use DoctrineDatabase::ping() — which is what DatabaseManager::recycleConnections() calls at the request boundary.

ThrowsWhen
DatabaseExceptionIf shutting the connection down fails.

public function shutdown(): mixed

Rolls back any open transaction, closes the DBAL connection and drops the entity manager.

A failure to roll back or close is logged at warning and does not stop the shutdown; the entity manager 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.
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.