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

  • Holy **** Google #chrome is fast with Web Outlook 15 years 10 weeks ago
  • @gavinbrook @casablanca You could buy a better mac and put #ubuntu on it and then put project on it 15 years 10 weeks ago
  • I dream of a cross between, #Eclipse, #netbeans, #textmate, #kate and #kdevelop 15 years 11 weeks ago
  • Nothing better than a shish kebab after a long cycle ride home in the rain. Extra chilies please! 15 years 12 weeks ago
  • @philpeace Apparently in the Qwerty keyboard, the letters t-y-p-e-w-r-i-t-er are all on the top row to allow sales men to type it quickly. 15 years 12 weeks ago
  • Anybody know how to enable a views block programattically? #drupal 15 years 13 weeks ago
  • Nice, especially like the <new [content type]> option too ♻ @drupalninja: menu editor module: http://drupal.org/project/menu_editor #drupal 15 years 13 weeks ago
  • You know CSS hasn't been written correctly when you have to write more for the same thing on a different page. 15 years 13 weeks ago
Oliver Polden