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

  • @Casablanca Is javascript disabled in your browser? 13 years 41 weeks ago
  • Been listening to my loved #lastfm tracks for the past week via the chrome plugin goo.gl/kF48s and now my Recommended tracks are awesome! 13 years 41 weeks ago
  • @Casablanca I'm proud! 13 years 42 weeks ago
  • HTML5 Presentations make me happy, especially when they're about HTML5 goo.gl/Fx9Sp 13 years 43 weeks ago
  • @philhawksworth goo.gl/TLwWd 13 years 43 weeks ago
  • @philhawksworth for some reason I imagine you walking around with a monocle in one eye, pointing at code and stuff with a cane! 13 years 44 weeks ago
  • Ooh, the #ux prototyping in code bootcamp looks good http://www.uxbootcamp.org/ Go code! How about prototyping in #Drupal? 13 years 48 weeks ago
  • @markboulton You could do it with #Drupal n/o premium module goo.gl/JLUxN and the role sub module of Ubercart goo.gl/z4mxT goo.gl/dZ0SF 13 years 48 weeks ago
Oliver Polden