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

  • @drupalninja yes I think that's what I did. Actually, I think that's still a table view and I overrode the table template. 15 years 21 weeks ago
  • @drupalninja I did it here on views 2: http://2tu.us/1l77 15 years 21 weeks ago
  • @drupalninja I think you can have a look at the links the table view produces and then just add the same links yourself 15 years 21 weeks ago
  • huh, is it only Konqueror that tells you if a link will open in a new window? 15 years 21 weeks ago
  • Mac dvi adapter needed. #Mac #Fosdem #fail 15 years 22 weeks ago
  • RT @Casablanca: RT @philhawksworth Hoping to find a #Drupal Legend at #fosdem to join us working at @TheTeam in London 15 years 22 weeks ago
  • Doing my put to put a nail in the coffin for IE6 http://2tu.us/1ja7 15 years 22 weeks ago
  • @leisa, is your javascript turned off? 15 years 23 weeks ago
Oliver Polden