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

  • http://t.co/oHKBnJn Dratman 14 years 3 weeks ago
  • 3 mobile email support not very fast! "We’ll get back to you within ten days" 14 years 4 weeks ago
  • Just learned about the great advantages of 'Using Per-Table Tablespaces' for innodb mysql tables. goo.gl/Xm8KZ Reclaiming disk space & more 14 years 4 weeks ago
  • Oooh, Amazon Kindle cloud reader: http://t.co/RYRLw68 14 years 4 weeks ago
  • Just pointed out to my boss: "You spelt 'gobbledegook' wrong." 14 years 6 weeks ago
  • OMG! opening <div>s in various files, and closing </div>s in various other files! Time to clean that up! 14 years 7 weeks ago
  • How come only now after all these years am I using the #Drupal format_plural() and Drupal.formatPlural() functions? 14 years 7 weeks ago
  • Why do I see so much custom #drupal code with comments such as: "Sorry I had to do it like this because Drupal won't do it" Yes it will! 14 years 7 weeks ago
Oliver Polden