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

  • Delving into LyX and LaTeX. So far I love it! One of those programs that is indisputably the best. 14 years 4 weeks ago
  • @Casablanca Come say hi! Lunch?! 14 years 4 weeks ago
  • Just seen: while($d = db_fetch_object($data)) { $_d = (array)$d; ... What's wrong with: while($d = db_fetch_array($data)) { ... 14 years 4 weeks ago
  • "Mark seems to understand Oliver perfectly..." Mark: "I do have two small children!" 14 years 4 weeks ago
  • If you're at a concert and your alarm goes off, don't hit snooze! 14 years 5 weeks ago
  • #google why can't I do something like this? 1293840000 unixtime in human readable date 14 years 5 weeks ago
  • @Casablanca I cycled to work today. 1 mile, 10 mins, not bad. 14 years 5 weeks ago
  • Doing the #drupal full project application. A warm fuzzy feeling from finally contributing back properly and great feedback from my reviewer 14 years 5 weeks ago
Oliver Polden