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 41 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? 15 years 45 weeks ago
  • @bridgecourt Modx 1.0 15 years 46 weeks ago
  • Giving Modx a go. First impressions: install 'ok', responsive javascript admin interface. with nice tree nav of site. Nod test = good. 15 years 46 weeks ago
  • Front End Drupal mentions the Textimage module. Will be giving that a try soon: http://2tu.us/m6n 15 years 48 weeks ago
  • Why haven't I found this before?!! Firebug for ie. My life just got a lot easier. http://2tu.us/li0 15 years 49 weeks ago
  • Drupal's looking good: http://bit.ly/rKrpS 15 years 49 weeks ago
  • Taking a look at kompozer. OS alternative to Dreamweaver for win, lin & mac :-) http://www.kompozer.net 15 years 51 weeks ago
Oliver Polden