If you need to inspect Magento’s configured database connection from code, you can load Magento and read the default_setup resource connection.

On Linux, a simple PHP file can look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php
require_once "/home/cliper/magento/app/Mage.php";
Mage::app();

$config = Mage::getConfig()->getResourceConnectionConfig("default_setup");

$dbinfo = array(
    "host"   => $config->host,
    "user"   => $config->username,
    "pass"   => $config->password,
    "dbname" => $config->dbname,
);
?>

In this example, /home/cliper/magento/ is the absolute path to the Magento installation.

On Windows, adjust the include path accordingly:

1
require_once "C:\\magento\\path\\app\\Mage.php";

After that, you can read individual values like this:

1
echo $dbinfo["host"];