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

  • Day one of my Drupalipet from the Drupal 7 release party. http://twitgoo.com/1ta7eo 14 years 18 weeks ago
  • At Drupal 7 release party. Can't wait to start using it. Didn't realise how much Microsoft is supporting it! #d7rp_london 14 years 18 weeks ago
  • Drupal 7 is out and I'm the third that commented! http://buytaert.net/drupal-7.0-released #drupal7 14 years 19 weeks ago
  • http://twitgoo.com/1sfadf my attempt at a snowman 14 years 20 weeks ago
  • I signed the "KDE4 as the default environment in Ubuntu" petition! http://petol.org/ubuntu4 #petol 14 years 25 weeks ago
  • @eventsacademy will you be putting your video up on youtube? 14 years 36 weeks ago
  • Extremely impressed with @eventsacademy tonight. Simply amazing what they have achieved. More on the site http://eventsacademy.org.uk/ 14 years 36 weeks ago
  • Ooh... a very compelling reason to finally get a new (Google) tv http://bit.ly/c91D6x 14 years 37 weeks ago
Oliver Polden