Note to self: Use db_set_active() to switch databases in Drupal
olav — Wed, 08/20/2008 - 13:00
If you use Drupal as a toolbox to implement a nice admin interface and your database administrator gets annoyed about the many tables Drupal uses, you can bracket your database code with calls to db_set_active(‘mydb’) like so:
db_set_active(‘mydb’);
// code that uses your existing database
db_set_active(‘default’);
In your sites/default/settings.php, you need to make $db_url an array like so:
$db_url = array( 'default' => 'mysql://your:drupal@tables.live/here', 'mydb' => 'mysql://all:your@other.tables.are/here', );




I can't get this to work
Anonymous — Thu, 04/02/2009 - 00:40I can’t get this code to work for me. I put my php code in a block and the block doesn’t return any data. Could you supply a working example. I can send you my code if you want to look it over.