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 15 years 10 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 15 years 11 weeks ago
  • Drupal 7 is out and I'm the third that commented! http://buytaert.net/drupal-7.0-released #drupal7 15 years 11 weeks ago
  • http://twitgoo.com/1sfadf my attempt at a snowman 15 years 13 weeks ago
  • I signed the "KDE4 as the default environment in Ubuntu" petition! http://petol.org/ubuntu4 #petol 15 years 18 weeks ago
  • @eventsacademy will you be putting your video up on youtube? 15 years 29 weeks ago
  • Extremely impressed with @eventsacademy tonight. Simply amazing what they have achieved. More on the site http://eventsacademy.org.uk/ 15 years 29 weeks ago
  • Ooh... a very compelling reason to finally get a new (Google) tv http://bit.ly/c91D6x 15 years 30 weeks ago
Oliver Polden