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

  • http://twitgoo.com/1tvsbl day 12 time for a hair cut 14 years 16 weeks ago
  • http://twitgoo.com/1tr5up day 8 14 years 16 weeks ago
  • http://twitgoo.com/1tprol day 7 14 years 17 weeks ago
  • Day 5 of my #drupalipet from #drupal7 release party http://twitgoo.com/1tn9lv 14 years 17 weeks ago
  • I friend has just tried xkcd on kindle. An amazed smile of joy and surprise has spread across his face. My turn please. 14 years 17 weeks ago
  • No I didn't :( i blame 3 14 years 17 weeks ago
  • I beat the iPhone 14 years 17 weeks ago
  • Won the quiz! 14 years 17 weeks ago
Oliver Polden