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

  • A great post about how the education system doesn't teach us how to be successful and follow our passions http://t.co/GsOpEUhj 12 years 16 weeks ago
  • @mattfarina how about em? 12 years 17 weeks ago
  • More about Omega here: http://t.co/kT7p1QSb 12 years 17 weeks ago
  • Delta + Omega + Context is probably one of the best things to happen to Drupal since Views 12 years 17 weeks ago
  • Wow! Just did a fresh install of Kubuntu Oneiric and I'm astonded. Very fast, very nice and lots of "oooh that's nice" 12 years 17 weeks ago
  • A great infographic about how Google works: http://t.co/dyZgxu3E 12 years 18 weeks ago
  • Just received my nexus 9000 silent mouse. First impressions, verrrrry nice, perhaps should have bought the 8000 tho: http://t.co/CzJB31bR 12 years 18 weeks ago
  • I've barely used GIT but already SVN seems archaic 12 years 18 weeks ago
Oliver Polden