Connect Drupal to external data base
You will need to add the following configuration in your settings.php file

$databases = array();
$databases['default']['default'] = array(
  // Drupal's default credentials here.
);
$databases['my_other_db']['default'] = array(
  // Your secondary database's credentials here.
);


Refer to settings.php for the array options.

Now if you are using a custom module you can use the following in  your module to switch between the 2 db's

// Use the database we set up earlier
db_set_active('my_other_db');


and if you want to move back to the default db

// Go back to the default database,
// Remember to go back to the drupal default version or drupal will not be able to access its data
db_set_active();


Also refer to https://drupal.org/node/18429 for more information.

There is one more of doing it if you do not want to do the db_set_Active() all the time.

So you define the connection in your settings.php like in the first step. Then in the module you can directly do the following

$query = Database::getConnection('default', 'my_other_db')
           -&gt;select('source_table', 'st')
...