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

  • @darthsteven or disabled javascript? 15 years 50 weeks ago
  • Having a look at Drupal 7 makes me wanna ditch my efforts to evaluate modx for 'smaller' sites. Is it familiarity or is Drupal just better? 16 years 2 weeks ago
  • @bridgecourt Modx 1.0 16 years 3 weeks ago
  • Giving Modx a go. First impressions: install 'ok', responsive javascript admin interface. with nice tree nav of site. Nod test = good. 16 years 3 weeks ago
  • Front End Drupal mentions the Textimage module. Will be giving that a try soon: http://2tu.us/m6n 16 years 6 weeks ago
  • Why haven't I found this before?!! Firebug for ie. My life just got a lot easier. http://2tu.us/li0 16 years 6 weeks ago
  • Drupal's looking good: http://bit.ly/rKrpS 16 years 6 weeks ago
  • Taking a look at kompozer. OS alternative to Dreamweaver for win, lin & mac :-) http://www.kompozer.net 16 years 8 weeks ago
Oliver Polden