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

  • search for 'search' on google.com and bing comes up first!?!?!?! 13 years 33 weeks ago
  • A genius, high value tip/test for #Drupal #continuousintegration with #Jenkins and #selenium if I do say so myself goo.gl/IGIy5 13 years 33 weeks ago
  • @philhawksworth Damn it! Someone beat me to it! 13 years 34 weeks ago
  • A short post I just wrote on setting up #Memcache for #Drupal: goo.gl/2VnUc 13 years 35 weeks ago
  • Seems ftp.drupal.org is down, but you can still download modules by hacking the download link to remove ftp. #drupal 13 years 35 weeks ago
  • dear #lazyweb #phpundercontrol ( #cruisecontrol ) or #jenkins for #drupal #continuousintegration 13 years 36 weeks ago
  • You've got to have some nuts to do this: goo.gl/TKqIe 13 years 36 weeks ago
  • http://t.co/q8CiVNc Dratman #drupal 13 years 36 weeks ago
Oliver Polden