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

  • @Casablanca Looks like a great time last night. Sorry I couldn't make it :( 12 years 28 weeks ago
  • Our new homepage is live http://t.co/iwNX1tWZ 12 years 29 weeks ago
  • Can you help with conditionally setting the 'from' in mails sent with notifications/messaging modules #drupal http://t.co/ItE75IlW 12 years 29 weeks ago
  • My post about highjacking #Drupal menu items with 'drupal_get_form' callbacks for creating popups or #ahah goodness http://t.co/Pe9wSz6k 12 years 30 weeks ago
  • Oh the conflict within. An entire section of a #drupal site was built bespoke, do I add a bespoke subsection, or rewrite the entire section? 12 years 33 weeks ago
  • @psd It depends. Serving static pages means https has a larger relative impact. If there's a lot of processing, https is relatively small. 12 years 33 weeks ago
  • Just had a play with the #drupal Field collection module. goo.gl/p6sEn A really nice Drupal 7 implementation of the multigroup module. 12 years 33 weeks ago
  • @philhawksworth @a_alfredo When will scampcat have the descriptions pop up when you hover over the markers? 12 years 34 weeks ago
Oliver Polden