I did this recently and this is how:
In your _config.php you create two db connection settings, something along these lines:
global $databaseConfig;
$databaseConfig = array(
'type' => 'MySQLDatabase',
'server' => 'localhost',
'username' => 'usernameA',
'password' => 'passwordA',
'database' => 'databaseA'
);
global $databaseConfig2;
$databaseConfig2 = array(
'type' => 'MySQLDatabase',
'server' => 'localhost',
'username' => 'usernameB',
'password' => 'passwordB',
'database' => 'databaseB'
);
Then in a function where you need both DBs, you do something like this:
public function doStuff() {
global $databaseConfig, $databaseConfig2;
// connect to DB 2
DB::connect($databaseConfig2);
// create a query.. this will go to "databaseB"
$query = new SQLQuery("*", "MyTable");
$result = $query->execute();
// do something with the result...
// when done, switch back to the regular DB Config
DB::connect($databaseConfig);
}