• ABOUT THIS SITE
  • MY CV
  • MY SOCIAL STREAM
  • CONTACT
  • SEARCH

olav.net

  • content
  • technology
  • life
  • bonn
Home

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',
);
  • Drupal
  • master / slave databases
  • Add new comment

I can't get this to work

Anonymous — Thu, 04/02/2009 - 00:40

I 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.

  • reply

Praxiswissen Drupal 6. oreillys basics

Mein Buch ist erschienen:

Image of Praxiswissen Drupal 6. oreillys basics

Hier ist die Zusammenfassung.

Mitglied der Drupal Association

Navigation

  • Recent posts

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password

Kommentiert

  • Känguru weiß es
    5 weeks 1 day ago
  • Yipeeh, bald ist es wieder soweit
    5 weeks 1 day ago
  • Man arrangiert sich
    5 weeks 1 day ago
  • NIce
    12 weeks 21 min ago
  • Geiler Pullover! Ob das bei
    13 weeks 1 day ago
  • Re: Atheist
    20 weeks 6 days ago
  • Portal
    36 weeks 3 hours ago
  • Endlich sagt's mal jemand...
    38 weeks 4 days ago
  • I can't get this to work
    49 weeks 3 days ago
  • ach so… wir sind hier nicht
    1 year 3 weeks ago

Freunde

Powered by Drupal, an open source content management system
  • content
  • technology
  • life
  • bonn