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