Getting the active database in Drupal

Sometimes when you're debugging you might want to check which is the currently selected database. The following code will print out the current database to the messages area:

<?php
drupal_set_message
(db_result(db_query('select database()')));
?>

Drupal 7 version <?php $m =

Drupal 7 version

<?php$m = db_query('select database() as base')                    ->fetchObject();watchdog('called', "The database is @var", array('@var' => $m->base));?>

I haven't tested this but

I haven't tested this but thanks for the comment!

Oliver

Post new comment

By submitting this form, you accept the Mollom privacy policy.

User login

Author of...

  • Let down by #phpstorm :-( no icon decorations on folders for version control status. Vote for it here: goo.gl/U6zRU 13 years 48 weeks ago
  • Having fun with #javascript, I mean #jquery, actually, I mean both :-p 13 years 49 weeks ago
  • Bitten by godaddy again, after a long time trying to make sense of my account I see I finally have nothing left on it. Bye bye! 13 years 49 weeks ago
  • ooh, jet profiler for mysql is pretty sweet 13 years 50 weeks ago
  • Here's some light friday afternoon reading, 26 Terabits per second: goo.gl/64ClB 13 years 50 weeks ago
  • A quick blog about setting up automated #Selenium testing with #Jenkins goo.gl/RQgaC 13 years 51 weeks ago
  • #ubuntu #gnome #canonical What features do you love that a KDE user should know about? Looking to add to my blog: goo.gl/Xmlk2 13 years 51 weeks ago
  • @philhawksworth I get the feeling you're going to start talking to yourself soon! 13 years 51 weeks ago
Oliver Polden