How do I connect to a database outside of Drupal?
There are steps listed out in this Drupal.org page:
- Define the secondary Database in your "settings.php",
- Switch to the Database inside of your module,
- Query that database,
- Swap back to the default Database when finished.