How to get database detail in Magento 2

Integrate Magepack with Magento/Adobe commerce

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.

Magento 2 convert an array to a collection object

Like us on Facebook and Linkedin for more updates.

Leave a Reply

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

Back To Top