<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
contaoblackforest / contao-doctrine-dbal example snippets
class MyClass
{
public function myFunc()
{
global $container;
/** @var \Doctrine\DBAL\Connection $connection */
$connection = $container['doctrine.connection.default'];
$connection->query('...');
}
}
$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);
}
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.