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