Switch between databases
You can, of course, use the database API that comes with PHP.

To use Drupal's database API, configure your databases as described in How to connect to multiple databases within Drupal and use db_set_active() to switch between databases.