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

  • Very impressed with yell's 3D maps, simply amazing: http://www.yell.com/maps/ 15 years 9 weeks ago
  • So much compelling about #ubuntu #lucid, but at the same time, stuff I can't live without in #kubuntu that deffinitely isn't in ubuntu 15 years 10 weeks ago
  • Scratch that! #ubuntu does have mouse wheel volume control, just not with the thingy open ooooooh! 15 years 10 weeks ago
  • Ok, lucid #ubuntu still doesn't let you control volume with your mouse wheel via the system tray icon, dissappointing 15 years 10 weeks ago
  • The Gimp resynthesizer plugin came in handy quicker than I thought it would: http://2tu.us/1xx3 15 years 12 weeks ago
  • Ohh, content-aware fill in #CS5, oooooooohhhhhhh, resynthesizer already been in Gimp for years: http://2tu.us/1xx3 15 years 12 weeks ago
  • @drupalninja There's a module for that! http://2tu.us/1xw4 15 years 13 weeks ago
  • See, programming by trial and error is foolproof... if you don't give up. 15 years 14 weeks ago
Oliver Polden