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