Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Tweeted twitter.com/#!/StackDrupal/status/128638827035234304
Source Link
Whiskey
  • 1.4k
  • 2
  • 20
  • 39

How to define and use an external database connection in a custom module

I'm developing a module that will rely heavily on external database queries. Is there a best practice for defining and using an external database connection throughout a module?

This page tells me how to make the connection, but not where to put it in a module (specific hook?) so I only have to define it once. Also, is it always necessary to do "db_set_active('YourDatabaseKey');" or can I pass an argument that will set the db to use? I'm using Drupal 7.