How to get the database name programmatically

database
(Dmitry Fedyuk) #1
use Magento\Framework\Config\ConfigOptionsListConstants;
/** @return string */
function rm_db_name() {
	/** @var string $result */
	static $result;
	if (!$result) {
		/** @var \Magento\Framework\ObjectManagerInterface $om */
		$om = \Magento\Framework\App\ObjectManager::getInstance();		
		/** @var \Magento\Framework\App\DeploymentConfig $config */
		$config = $om->get('Magento\Framework\App\DeploymentConfig');
		/** https://github.com/magento/magento2/issues/2090 */
		$result = $config->get(
			ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT
			. '/' . ConfigOptionsListConstants::KEY_NAME
		);
	}
	return $result;
}
0 Likes

(Yaminee Sowri) #2

In the same way i want to know the host name and password.

Will you please send code

0 Likes