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

  • The A-Team, a bit annoying but enjoyable. Why did they not play the classic soundtrack?! 14 years 48 weeks ago
  • Google maps track of my solo flight http://is.gd/dHTlr 14 years 49 weeks ago
  • First solo flight, ride to work voucher arrived. My shiny new bike awaits. It's been a good day. Night out to finish it off I think. 14 years 50 weeks ago
  • Successfully just did my first glider solo! 14 years 50 weeks ago
  • @leisa not the one here?! How quick is google! http://bit.ly/9e742A 14 years 50 weeks ago
  • A quick blog about typography and ligatures: http://oliverpolden.com/balancing-seo-and-design-ligatures 15 years 1 week ago
  • Going back to #kubuntu from #ubuntu. File already exists: Cancel, Skip, Replace, where is rename?! http://bit.ly/aYWWYk 15 years 2 weeks ago
  • less than a month to go until Microsoft stop supporting IE6 Wohoo! http://support.microsoft.com/gp/lifesupsps/#Internet_Explorer 15 years 3 weeks ago
Oliver Polden