PHPackages                             contaoblackforest/contao-doctrine-dbal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. contaoblackforest/contao-doctrine-dbal

ActiveContao-module[Database &amp; ORM](/categories/database)

contaoblackforest/contao-doctrine-dbal
======================================

Doctrine DBAL Bridge for Contao Open Source CMS

1.2.0(7y ago)12.3k3[2 issues](https://github.com/ContaoBlackForest/contao-doctrine-dbal/issues)[1 PRs](https://github.com/ContaoBlackForest/contao-doctrine-dbal/pulls)2LGPL-3.0-or-laterPHPPHP ^5.6 || ^7.0

Since Apr 28Pushed 7y ago3 watchersCompare

[ Source](https://github.com/ContaoBlackForest/contao-doctrine-dbal)[ Packagist](https://packagist.org/packages/contaoblackforest/contao-doctrine-dbal)[ RSS](/packages/contaoblackforest-contao-doctrine-dbal/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (8)Used By (2)

Doctrine DBAL Bridge
====================

[](#doctrine-dbal-bridge)

This extension provide [Doctrine DBAL](http://www.doctrine-project.org) in the [Contao Open Source CMS](http://contao.org). It only provide a service `$container['doctrine.connection.default']` to connect the default database with Doctrine DBAL. To use the Doctrine Connection within the Contao Database Framework, use [bit3/contao-doctrine-dbal-driver](https://github.com/bit3/contao-doctrine-dbal-driver).

Use the doctrine connection
---------------------------

[](#use-the-doctrine-connection)

```
class MyClass
{
	public function myFunc()
	{
		global $container;
		/** @var \Doctrine\DBAL\Connection $connection */
		$connection = $container['doctrine.connection.default'];

		$connection->query('...');
	}
}
```

Contao hooks
------------

[](#contao-hooks)

`$GLOBALS['TL_HOOKS']['prepareDoctrineConnection'] = function(&$connectionParameters, &$config) { ... }`Called before the connection will be established.

`$GLOBALS['TL_HOOKS']['doctrineConnect'] = function(&$connection) { ... }`Called after the connection is established.

Define a custom connection
--------------------------

[](#define-a-custom-connection)

We prefer to use the [dependency injection container](https://github.com/bit3/contao-dependency-container): Write a `system/config/services.php` or `system/modules/.../config/services.php`:

```
$container['doctrine.connection.default'] = $container->share(
	function ($container) {
		$config = new \Doctrine\DBAL\Configuration();

		$connectionParameters = array(
			'dbname'   => $GLOBALS['TL_CONFIG']['dbDatabase'],
			'user'     => $GLOBALS['TL_CONFIG']['dbUser'],
			'password' => $GLOBALS['TL_CONFIG']['dbPass'],
			'host'     => $GLOBALS['TL_CONFIG']['dbHost'],
			'port'     => $GLOBALS['TL_CONFIG']['dbPort'],
		);

		switch (strtolower($GLOBALS['TL_CONFIG']['dbDriver'])) {
			// reuse connection
			case 'doctrinemysql':
				return \Database::getInstance()->getConnection();

			case 'mysql':
			case 'mysqli':
				$connectionParameters['driver']  = 'pdo_mysql';
				$connectionParameters['charset'] = $GLOBALS['TL_CONFIG']['dbCharset'];
				if (!empty($GLOBALS['TL_CONFIG']['dbSocket'])) {
					$connectionParameters['unix_socket'] = $GLOBALS['TL_CONFIG']['dbSocket'];
				}
				break;
			default:
				throw new RuntimeException('Database driver ' . $GLOBALS['TL_CONFIG']['dbDriver'] . ' not known by doctrine.');
		}

		if (!empty($GLOBALS['TL_CONFIG']['dbPdoDriverOptions'])) {
			$connectionParameters['driverOptions'] = deserialize($GLOBALS['TL_CONFIG']['dbPdoDriverOptions'], true);
		}

		return \Doctrine\DBAL\DriverManager::getConnection($connectionParameters, $config);
	}
);
```

Configure caching
-----------------

[](#configure-caching)

The caching implementation is defined in `$container['doctrine.cache.impl.default']` (default: `auto`). By default, the caching implementation is detected by default, try this implementations in order: APC, Xcache, memcache, Redis, Array.

Possible settings are:

apcuse apc cachexcacheuse xcache cachememcache://\[:\]use memcache cache on :redis://\[:\]use redis cache on :redis://use redis cache on filearrayuse array cacheThe caching time to live is defined in `$container['doctrine.cache.ttl.default']` (default: 0).

The caching key is defined in `$container['doctrine.cache.key.default']` (default: `contao_default_connection`).

To disable caching, set `$container['doctrine.cache.profile.default'] = null;`.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 79.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~322 days

Recently: every ~393 days

Total

6

Last Release

2791d ago

PHP version history (2 changes)1.1PHP &gt;=5.3

1.2.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/233a03a2e2f9a5043fc57a6bf4ae998a2364a64a18a1263bdc11167ffb86cba8?d=identicon)[baumannsven](/maintainers/baumannsven)

![](https://www.gravatar.com/avatar/267ed97e6ff0d8bfb21dc496315426148362bf7cac913c824501d7ed97cd1c41?d=identicon)[dtomasi](/maintainers/dtomasi)

---

Top Contributors

[![tristanlins](https://avatars.githubusercontent.com/u/343404?v=4)](https://github.com/tristanlins "tristanlins (27 commits)")[![baumannsven](https://avatars.githubusercontent.com/u/2493263?v=4)](https://github.com/baumannsven "baumannsven (7 commits)")

---

Tags

doctrinedbalcontao

### Embed Badge

![Health badge](/badges/contaoblackforest-contao-doctrine-dbal/health.svg)

```
[![Health](https://phpackages.com/badges/contaoblackforest-contao-doctrine-dbal/health.svg)](https://phpackages.com/packages/contaoblackforest-contao-doctrine-dbal)
```

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[jsor/doctrine-postgis

Spatial and Geographic Data with PostGIS and Doctrine.

2191.6M1](/packages/jsor-doctrine-postgis)[larapack/doctrine-support

Better Doctrine Support with Laravel (Support for `enum`)

1752.3M55](/packages/larapack-doctrine-support)[friendsofdoctrine/dbal-clickhouse

Doctrine DBAL driver for ClickHouse

1141.2M1](/packages/friendsofdoctrine-dbal-clickhouse)[enqueue/dbal

Message Queue Doctrine DBAL Transport

246.3M8](/packages/enqueue-dbal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
