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

  • Yes. If you want to torture me put me on a locked down windows computer with a locked down network and no power for a day. 15 years 16 weeks ago
  • can someone please #invent a mobile phone where the camera can double as an optical mouse 15 years 18 weeks ago
  • @philhawksworth don't you mean thank goodness for @oliverpolden too :p 15 years 18 weeks ago
  • What's #Debian like nowadays compared to #Ubuntu ? 15 years 18 weeks ago
  • @gavman80s Pidgin will do all that and more and has done for years: http://2tu.us/1pha 15 years 18 weeks ago
  • that doesn't work if no other checkboxes are checked by default #drupal contact-us?edit[submitted][mycheckboxes][0]=mycheckbox 15 years 20 weeks ago
  • ahh, something like: contact-us?edit[submitted][mycheckboxes][0]=mycheckbox 15 years 20 weeks ago
  • Is it possible to use the prepopulate module to check a checkbox on a webform? #drupal 15 years 20 weeks ago
Oliver Polden