codeFragment codeFragment - 1 month ago 14
PHP Question

TYPO3 own file for database connection

I tried to take out my database connection from the LocalConfiguration. But it doesn't work on this way. Do you have any ideas how i can realize it. Here what i tried to make it work:

LocalConfiguration.php:

<?php
include_once 'databaseConn.php';
return [
'BE' => [
'debug' => false,
'explicitADmode' => 'explicitAllow',
'installToolPassword' => '$P$CcKE/MYkjKWDzNWsnVZhMBDAttVVrf.',
'loginSecurityLevel' => 'rsa',
],


and in the databaseConn.php:

<?php
$TYPO3_CONF_VARS['DB']['database'] = 'db_name';
$TYPO3_CONF_VARS['DB']['host'] = 'localhost';
$TYPO3_CONF_VARS['DB']['password'] = 'password';
$TYPO3_CONF_VARS['DB']['socket'] = '';
$TYPO3_CONF_VARS['DB']['username'] = 'usr_name';


Hope you can help me.

thanks
Chris

Answer

Create a file called AdditionalConfiguration.php in same directory. You can override every value there by addressing it directly

$GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = 'custom';

You can also check the ApplicationContext by $context = GeneralUtility::getApplicationContext()->__toString(); which can be set in a .htaccess or vhost config

Comments