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:

(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!


Post new comment

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

User login

Author of...

  • Did you know today is world peace day? 6 years 48 weeks ago
  • If you would like to donate to Sport relief and change people's lives the address is: 7 years 21 weeks ago
  • Why big businesses cannot compete with small businesses: 7 years 24 weeks ago
  • The newest addition to my kindle: 'Know Me, Like Me, Follow Me' - Social networking for business by @pennypower 7 years 25 weeks ago
  • Using YouTube videos to improve your exposure and credibility 7 years 25 weeks ago
  • Penny power making great points about social media being personal #kpiday 7 years 25 weeks ago
  • @philhawksworth Yes, I lust after kate 7 years 27 weeks ago
  • Monday the 13th is the new Friday 13th. 7 years 27 weeks ago
Oliver Polden