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

  • Where is my parcel #homedeliverynetwork #hdnl You said it would be here between 9.38 and 12.38, it's now 12.48. 14 years 7 weeks ago
  • oh joy, that didn't take long. Debugging in IE, the pain begins. 14 years 7 weeks ago
  • New colleagues are only whelmed by links2 graphics mode, why would you want a text browser with images? #true 14 years 7 weeks ago
  • 1 pint Oliver has had two :-) 14 years 7 weeks ago
  • Oh my god PhpStorm is an amazing IDE! Everything I ever wanted netbeans and eclipse to be. 14 years 7 weeks ago
  • omg www.nowthatsmusic.com is definitely not the www.nowmusic.com that I built. 14 years 7 weeks ago
  • @philhawksworth lol, have you fixed that swap bug yet? 14 years 7 weeks ago
  • Watching Jamie's dream school and remembering how much fun it was to work with Nana @kwame25 not to mention how impressed. 14 years 8 weeks ago
Oliver Polden