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

  • @casablanca @philhawksworth ohhhh, ahhhh, argh! 14 years 5 weeks ago
  • What the? Updating two packages on Kubuntu... 4 minutes remaining... oh, one of them is #Skype. 14 years 5 weeks ago
  • Thanks @gavinbrook Seems #woopra is the only one that does more than monitoring. The tagging users feature looks very useful. 14 years 6 weeks ago
  • Any votes for: #woopra #chartbeat #mixpanel or #clicky or any other #realtimeanalytics suggestions? 14 years 6 weeks ago
  • Ohh, just having a look at the git instructions for my own Drupal project. Learning a lot about git in the process : -) goo.gl/ZKBo7 14 years 6 weeks ago
  • @philhawksworth @philpeace I'm slowly moving all my sites off Godaddy too but they don't have a proper way of transferring .co.uk sites!!! 14 years 6 weeks ago
  • enjoying a bit of javascript but what am I doing at late so work? 14 years 7 weeks ago
  • [GitHub] theteam added you to a team, lol 14 years 7 weeks ago
Oliver Polden