Drupal has support for multiple databases using settings.php as described here http://drupal.org/node/18429. Refactor all database calls to use this convention.