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 15 years 5 days ago
  • @leisa you need one of these: 3.ly/BVNU 15 years 5 days 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 15 years 5 days ago
  • Got out a new blank dvorak keyboard at my new place. Wasn't long to get the response I usually get :-) 15 years 5 days ago
  • @casablanca Budgens did it :-) Time for a bit of Urban Terror in a few minutes http://www.urbanterror.info 15 years 1 week ago
  • Beer O'Clock in an hour :-) ... oh :-( 15 years 1 week ago
  • I'm not religious but statements in the bible seem to have been accurate or at least reasonable for hundreds of years. 15 years 2 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 15 years 4 weeks ago
Oliver Polden