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

  • #drupal #seo audit Can be done automatically at: www.analyticsseo.com 14 years 7 weeks ago
  • The Conversation Prism: http://www.theconversationprism.com/1600x1200/ 14 years 7 weeks ago
  • My answer to the Kindle DX vs iPad vs some other tablet dilemma: goo.gl/YsVj1 14 years 7 weeks ago
  • @philhawksworth where, where can I do it again? Where?! What kind of sounds do they make [in your head]? 14 years 7 weeks ago
  • ahh, that's the puppy goo.gl/J6Zcc 14 years 7 weeks ago
  • Oooh, CardSave management system looks reminiscent of... can't quite put my finger on it: goo.gl/5sIXw 14 years 7 weeks ago
  • Coraline is seriously a PG? I'm scared! 14 years 8 weeks ago
  • Ooh that advert demonstrating bluray on my dvd player looks fantastic! I've got to get me some of that! Wtf 14 years 10 weeks ago
Oliver Polden