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

  • Wohoo, got my first #selenium login test running from #jenkins/#hudson 14 years 4 weeks ago
  • That's a really annoying ad, thanks #microsoft goo.gl/oX62O 14 years 4 weeks ago
  • #windows #mac #linux Can you turn your volume up/down using your mouse wheel on your system tray icon? Can you mute it with middle click? 14 years 4 weeks ago
  • Just received my Web Designer's Idea Book. Very worthwhile investment, although there's a two volume set I should have bought! 14 years 5 weeks ago
  • Interesting article about click distribution over search results: goo.gl/WOBRU #seo 14 years 5 weeks ago
  • Trying to find the apache vhost configuration for a site? apache2ctl -S 14 years 5 weeks ago
  • One small step for Google, one giant leap for IE6, Chrome Frame without needing admin rights: goo.gl/kBkEs /via @lmjabreu 14 years 5 weeks ago
  • @philhawsworth @casablanca @a_alfredo suddenly having a big pang of fussball mourning 14 years 5 weeks ago
Oliver Polden