How do I programmatically use an external database?
$databases = array();
$databases['default']['default'] = array(
// Drupal's default credentials here.
// This is where the Drupal core will store its data.
);
$databases['my_other_db']['default'] = array(
// Your secondary database's credentials here.
// You will be able to explicitly connect to this database from your modules.
);