Today, I’m sharing to you the “How to edit Magento 2 Database Configuration file” tutorial. When installing or changing hosting for your Magento store, editing database configuration file is really important
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.
Magento2 store database details in app/etc/env.php file
array ( 'host' => '127.0.0.1', 'dbname' => 'magento', 'username' => 'root', 'password' => '4gile-123', 'active' => '1', ),
Get database detail in root file
Create php file on root dir.
use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $deploymentConfig = $obj->get('\Magento\Framework\App\DeploymentConfig'); $data = $deploymentConfig->get('db/connection/default')); var_dump($data);
So I will keep it simple you can try this code in your custom.php file placed in Magento root folder.