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.
<initstatements>< ![CDATA[SET NAMES utf8]]></initstatements>
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.
$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
Hope you enjoyed the article and never forget to share to help others.
Latest posts by Jyotiranjan Biswal (see all)
- PHP Dependency Injection - September 28, 2017
- Magento 2 backend system configuration - September 24, 2017
- Magento 2 plugin Interceptors system - September 10, 2017
- flush cache and reindexing programatically in magento 2 - July 3, 2017
- confirm change event on confirmation for a dropdown - November 17, 2016