University of Oregon

Aegir: Adding external databases / injecting data in the settings.php file

I’ve been using Aegir a lot lately and it’s nice to find built-in work-arounds when you need one.
I needed to add an external database to my drupal site. As it turns out you can create a local.settings.php file in your site folder, and extend your settings.php file. See Injecting into settings.php for a full description.

Aegir manages the settings.php file. So any changes you make there will be overwritten. But we have control over the local.settings.php file.
As an example, I needed to include an external database that I incorporate into my site via TableWizard. To achieve that I created this local.settings.php file:

[code:php] ‘mysqli’,
‘database’ => ‘hr_ee_forms’,
‘username’ => ‘hr_reader’,
‘password’ => ‘******’,
‘host’ => ‘hrpub’,
‘port’ => ‘3306’,
$db_url[‘uo_ee_forms’] = $databases[‘uo_ee_forms’][‘default’][‘driver’] . ‘://’ . $databases[‘uo_ee_forms’][‘default’][‘username’] . ‘:’ . $databases[‘uo_ee_forms’][‘default’][‘password’] . ‘@’ . $databases[‘uo_ee_forms’][‘default’][‘host’] . ‘:’ . $databases[‘uo_ee_forms’][‘default’][‘port’] . ‘/’. $databases[‘uo_ee_forms’][‘default’][‘database’];

$db_prefix = array(
‘default’ => ”,
‘org_level’ => ”,/*org_chart*/
‘uo_oa’ => ”/*uo_ee_forms*/

The above code adds an external DB that TableWizard can read, providing access to the data via views.

Note that I had to ‘hard code’ the values. We can’t take advantage of the stored $_server vars that Aegir keeps in the vhost file. For ex:

$databases[‘default’][‘default’] = array(
‘driver’ => $_SERVER[‘db_type’],
‘database’ => $_SERVER[‘db_name’],
‘username’ => $_SERVER[‘db_user’],
‘password’ => $_SERVER[‘db_passwd’],
‘host’ => $_SERVER[‘db_host’],
‘port’ => $_SERVER[‘db_port’],

Those are available in the settings.php file but unset before the our local.settings.php file is run.

There’s also an option for a file that can apply settings to all your sites.

Installed Table Wizard

Installed Table Wizard and will start laying the foundation for running reports for Making Tracks