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

  • @iainfarrell oooh, better Ubuntu, that's nice 15 years 14 weeks ago
  • @philhawksworth: Looking for an amazing web developer to join @TheTeam with superb HTML, CSS and Javascript fu. Contact me if that's you. 15 years 14 weeks ago
  • @iainfarrell Do they use Photoshop in Canonical land? 15 years 15 weeks ago
  • Windows uninstall program: Checking for necessary disk space, oooook.... 15 years 15 weeks ago
  • @iainfarrell loving all the references 15 years 15 weeks ago
  • Glad that a week with far too much Windows pain is over 15 years 16 weeks ago
  • anyone ever had hook_mail not triggering? #drupal I've got mimemail, advanced contact and contact redirect installed 15 years 16 weeks ago
  • Enjoying my well spent £3 to listen to my #last.fm loved tracks for a month 15 years 16 weeks ago
Oliver Polden