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 13 years 37 weeks ago
  • 3 mobile email support not very fast! "We’ll get back to you within ten days" 13 years 38 weeks ago
  • Just learned about the great advantages of 'Using Per-Table Tablespaces' for innodb mysql tables. goo.gl/Xm8KZ Reclaiming disk space & more 13 years 38 weeks ago
  • Oooh, Amazon Kindle cloud reader: http://t.co/RYRLw68 13 years 38 weeks ago
  • Just pointed out to my boss: "You spelt 'gobbledegook' wrong." 13 years 40 weeks ago
  • OMG! opening <div>s in various files, and closing </div>s in various other files! Time to clean that up! 13 years 41 weeks ago
  • How come only now after all these years am I using the #Drupal format_plural() and Drupal.formatPlural() functions? 13 years 41 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! 13 years 41 weeks ago
Oliver Polden