Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Magento how do you get the database name?

How do you get the database name from Magento?

I have seen functions like the one below that can get the table name.

$orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');

I was hoping that there was some sort of function like this:

Mage::getSingleton('core/resource')->getDatabaseName();

Thanks in advance for any ideas.

like image 628
woot586 Avatar asked Jan 06 '11 12:01

woot586


People also ask

How to find the database name of your Magento 2 store?

Go to your store core folder and open the env.php file under the app/etc folder. Find the next code, where database_name is actual database name which you use for your Magento 2 store.

What is the difference between Magento 1 and 2?

The latest Magento 2 comes with not only improved security, performance, and ease of use but also some changes in the file structure. The configuration file differs from the one in Magento 1. For example:

How to clear the cache in Magento 2?

database_name: MySQL database name of Magento. After you’re done configuring, make sure to save the file and clear your cache by moving into your Magento backend and choosing System > Tools > Cache Management.> Flush Magento Cache. You will not find Env.php in the app/etc folder if you didn’t go through the Magento 2 installation process.

How to solve Magento 2 followsymlinks not working issue?

Besides, in the .htaccess file in your Magento 2 folder, you try replacing FollowSymlinks directives with SymlinkIfOwnwner . This should help solve this issue 2. Issues while establishing database connection when migrating your site to a new hosting


1 Answers

Each module can specify it's own connection so you are right to go via a model.

$config = Mage::getResourceModel('sales/order')->getConnection()->getConfig();
// $config is an array
$dbname = $config['dbname'];

If you're only interested in the default a slightly more efficient way might be:

$dbname = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/dbname');
like image 69
clockworkgeek Avatar answered Sep 30 '22 16:09

clockworkgeek