Using an external database with Drupal is very simple.

First, you must add the database to your settings.php file like so:

$db_url['default'] = 'mysqli://user:password@localhost/database_name';
$db_url['external'] = 'mysqli://user:password@localhost/database_name';

So, “default” is our regular Drupal database and “external” is an additional database. To switch to the “external” database, you would use this code:


db_set_active('external');

//Your code here

//*****then remember to SWITCH BACK TO DEFAULT DATABASE when done
db_set_active('default');

Easy as Pie!