bit3/contao-doctrine-dbal-driver

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
This package is abandoned and no longer maintained. The author suggests using the ContaoBlackForest/contao-doctrine-dbal-driver package instead.

Database Driver using Doctrine DBAL for Contao Open Source CMS

3.2.2 2015-06-10 07:02 UTC

README

To use this database driver, change the driver in your system/config/localconfig.php:

$GLOBALS['TL_CONFIG']['dbDriver'] = 'DoctrineMySQL';

Configure caching

By default, the driver use an array cache (equivalent to contao). But the caching can be configured with $GLOBALS['TL_CONFIG']['dbCache'], $GLOBALS['TL_CONFIG']['dbCacheTTL'] and $GLOBALS['TL_CONFIG']['dbCacheName'].

$GLOBALS['TL_CONFIG']['dbCache'] define the caching mechanism, possible values are:

apc use apc cache
xcache use xcache cache
memcache://<host>[:<port>] use memcache cache on <host>:<port>
redis://<host>[:<port>] use redis cache on <host>:<port>
redis://<socket> use redis cache on <socket> file
array use array cache
false disable the cache

$GLOBALS['TL_CONFIG']['dbCacheTTL'] is an integer value, that define the time to live (default value is 1 second for backend and 15 second for frontend).

$GLOBALS['TL_CONFIG']['dbCacheName'] is a string for uniq identify cache entries. This is useful if you have a shared cache like memcache (default value is md5(/absolute/path/to/bit3/contao-doctrine-dbal-driver/src/Contao/Doctrine/Driver/MySQL/Statement.php)).

Different caching in frontend and backend

You can add _FE or _BE to each cache config key, to define different caching in frontend and backend. For example $GLOBALS['TL_CONFIG']['dbCache_FE'] define the frontend caching mechanism and $GLOBALS['TL_CONFIG']['dbCacheTTL_BE'] define the backend caching time to live.

Accessing the doctrine dbal connection

If you have installed bit3/contao-doctrine-dbal, you should use the dependency injection container:

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

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

Alternatively you can get the connection from the database instance:

class MyClass
{
	public function myFunc()
	{
		/** @var \Doctrine\DBAL\Connection $connection */
		$connection = Database::getInstance()->getConnection();
	}
}