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

  • Here you go @leisa 3.ly/cH6X 14 years 8 weeks ago
  • @leisa you need one of these: 3.ly/BVNU 14 years 8 weeks ago
  • Delving deep into the Drupal services module, where exactly, and on which side is my code failing? Do like a challenge tho! 3.ly/2AcM 14 years 8 weeks ago
  • Got out a new blank dvorak keyboard at my new place. Wasn't long to get the response I usually get :-) 14 years 8 weeks ago
  • @casablanca Budgens did it :-) Time for a bit of Urban Terror in a few minutes http://www.urbanterror.info 14 years 8 weeks ago
  • Beer O'Clock in an hour :-) ... oh :-( 14 years 8 weeks ago
  • I'm not religious but statements in the bible seem to have been accurate or at least reasonable for hundreds of years. 14 years 9 weeks ago
  • I clicked a link to this on another site. Is it a joke? http://protectyourpcdata.co.uk/PDF/Data_Loss_Quotes_and_Statistics.pdf 14 years 12 weeks ago
Oliver Polden