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

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