I am integrating code that implements its own extension of PHP's PDO class, in the same way that Drupal's DatabaseConnection does. So this code (which is various data models) needs to use this non-drupal PDO object.

This code needs DSN, username and password to access the default drupal database. I noted that $databases, defined in settings.php is not available: global $databases does not work to give me access to that data.

Is there a way to ask Drupal for this info or extract it from the default connection object?

  • I've posted an initial answer, but how are you you integrating this script? Through a module? A separate PHP file?
    – Chapabu
    Oct 26, 2012 at 13:23

2 Answers 2


The following works perfectly for me in devel/php

global $databases;


It should return the full array of database information:

databases output

  • My bad, must have been doing something stupid, thank you! Oct 26, 2012 at 14:44

As shown by Chapabu global $databases does work but it wont work if you are using a separate PHP file (not related to Drupal Codebase), if you want to use it like that you need to include settings.php file before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.