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.
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.
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:
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.
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
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With