How do I connect to a database outside of Drupal?
There are steps listed out in this Drupal.org page:
- Define the second database in your "settings.php",
- which can then be switched to when you need to query it,
- then just swap back to the default database when finished.