To use this database driver, change the driver in your system/config/localconfig.php
:
$GLOBALS['TL_CONFIG']['dbDriver'] = 'DoctrineMySQL';
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)
).
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.
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();
}
}