2

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

codeFragment
  • 103
  • 1
  • 1
  • 12

3 Answers3

1

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

Georg Ringer
  • 7,779
  • 1
  • 16
  • 34
  • Hi Georg, thx for your answer. how would you solve my problem with git? because if i write this in the additional-file, then i have to ignore this file. but i just want to ignore one specific file with only the database connection. – codeFragment Oct 25 '16 at 11:30
1

Use the following code in AdditionalConfiguration.php:

$configurationSettings = array();
@include_once(__DIR__.'/DatabaseCredentials.php');
@include_once(… some other files …);
if (is_array($configurationSettings)) {
    foreach ($configurationSettings as $path => $value) {
        $GLOBALS['TYPO3_CONF_VARS'] = \TYPO3\CMS\Core\Utility\ArrayUtility::setValueByPath($GLOBALS['TYPO3_CONF_VARS'], $path, $value);
    }
}
unset($configurationSettings);

then set your database credentials in DatabaseCredentials.php:

$configurationSettings = array_merge($configurationSettings, array(
  'DB/database' => 'local_database',
  'DB/username' => 'local_username',
  'DB/password' => 'secret'
));

and you're done.

Wolfgang
  • 593
  • 3
  • 8
  • It would be easier to return the `$configurationSettings` in the `DatabaseCredentials.php` - no need for the `@` operator. If the database connection data is not available, a failure is the right thing to have. – Jost Oct 25 '16 at 14:48
  • You are right, in real life I have several files in a chain (and merge all these arrays with $configurationSettings, if you only need that for one single file, you can simplify it). If the file is missing on a server (like on the production system) it takes the values from LocalConfiguration.php … makes all sense imho to discard messages here. – Wolfgang Oct 25 '16 at 15:48
-2

It is better that you add your database connection code into "LocalConfiguration.php".

return array(
    'BE' => array(
        'debug' => false,
        'explicitADmode' => 'explicitAllow',
        'installToolPassword' => '$P$CcKE/MYkjKWDzNWsnVZhMBDAttVVrf.',
        'loginSecurityLevel' => 'rsa',
    ),
    'DB' => array(
        'database' => 'db_name',
        'extTablesDefinitionScript' => 'extTables.php',
        'host' => 'localhost',
        'password' => 'password',
        'socket' => '',
        'username' => 'username',
    ),
Vimal Usadadiya
  • 442
  • 2
  • 10
  • Hi but that's exactly what I won't. In fact of two different Databases - one local and one remote - i have two different connection and this file with the connection i want to ignore by git. that's why i want to exclude it from Local Configuration.php – codeFragment Oct 25 '16 at 10:04
  • Review below link it may be it will help in you. "http://stackoverflow.com/questions/18350213/typo3-ver-6-x-additional-configuration-a-k-a-localconf-local-php" – Vimal Usadadiya Oct 25 '16 at 10:52