Magento database connection details.
Magento database connection details.

Suppose you have only access of FTP and cPanel and you were not given which database is used in current project of magento. In that mean time how can a developer would get know which database has been use for magento site.Generally Magento database connection details can be found from local.xml file if you navigate app/etc/local.xml directory.Generally local.xml contains environment dependent settings like DB connection, cache engine, encryption key, session handler etc.So in local.xml file we will be getting all database connection details if we go through it.

Below xml file clearly explains all related values.If you thoroughly view then you will get all your requirement for accessing your database like which database has used and what are the credentials etc.Below code contains some values like

  • table_prefix: ”
  • host: ‘localhost’
  • username: ‘root’
  • password: ”
  • dbname: ‘magento’

You can change as per your server.

Local.xml
Dir: app/etc/local.xml

<resources>
    <db>
        <table_prefix>< ![CDATA[]]></table_prefix>
    </db>
    <default_setup>
        <connection>
            <host>< ![CDATA[localhost]]></host>
            <username>< ![CDATA[root]]></username>
            <password>< ![CDATA[]]></password>
            <dbname>< ![CDATA[magento]]></dbname>
            <initstatements>< ![CDATA[SET NAMES utf8]]></initstatements>
            <model>< ![CDATA[mysql4]]></model>
            <type>< ![CDATA[pdo_mysql]]></type>
            <pdotype>< ![CDATA[]]></pdotype>
            <active>1</active>
        </connection>
    </default_setup>
</resources>

You can get Magento database connection details through above code but you can create custom script to get database details as well.You can check below code that I had used in one of my project to get Magento database connection details.You can use this if you are not sure in case of local.xml file.Obviously if this script give you the same result with local.xml file then you will be sure yes I am using this database with these credentials.You can place this custom script in root directory of you magento installation and run through browser then you will be getting all details of your database.

< ?php
    require_once("app/Mage.php");
    Mage::app('default');
    try{
        $default_setup  = Mage::getConfig()->getResourceConnectionConfig("default_setup");
        $dbDetails = array("host" => $default_setup->host,
            "username" => $default_setup->username,
            "password" => $default_setup->password,
            "dbname" => $default_setup->dbname
        );
        print_r($dbDetails);
    }catch(Exception $e){
        echo $e;
    }
?>

Hope you enjoyed the article and never forget to share to help others.

Magento database connection details
Tagged on:                         

Leave a Reply

Your email address will not be published. Required fields are marked *