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

  • Ever wanted to create a CSS class or id from any old string in #Drupal? ctools_cleanstring() in the ctools module is your friend. 12 years 23 weeks ago
  • How to inspect the :active and :hover pseudo CSS style: http://t.co/zVANhKLp 12 years 24 weeks ago
  • @iainfarrell Good luck up north! 12 years 24 weeks ago
  • My most intriguing #Drupal utility modules out of 1030 for erm... Drupal 6, http://t.co/kmXV4qLp 12 years 24 weeks ago
  • #Chrome please can you check my hosts file before doing a search on an internet. Also, if I edit a url, yes that's still my local machine. 12 years 24 weeks ago
  • Seeing (not provided) in your Google Analytics?.. http://t.co/rSlpwm7U 12 years 25 weeks ago
  • Why SEO isn't evil http://t.co/MHh7ZHkK 12 years 25 weeks ago
  • @philhawksworth But that's unpossible! 12 years 26 weeks ago
Oliver Polden