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 13 years 51 weeks ago
  • That's a really annoying ad, thanks #microsoft goo.gl/oX62O 13 years 51 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? 13 years 51 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 2 days ago
  • Interesting article about click distribution over search results: goo.gl/WOBRU #seo 14 years 3 days ago
  • Trying to find the apache vhost configuration for a site? apache2ctl -S 14 years 4 days ago
  • One small step for Google, one giant leap for IE6, Chrome Frame without needing admin rights: goo.gl/kBkEs /via @lmjabreu 14 years 4 days ago
  • @philhawsworth @casablanca @a_alfredo suddenly having a big pang of fussball mourning 14 years 4 days ago
Oliver Polden