Note on Drupal best practices: when using db_set_active() to use another database, make sure to reset back to the default db as soon as you get the results from the other database. You can never be sure just when Drupal is gong to try another query that may need the default db.