I need to know the database name and database server name inside a symfony project. How can one access the current database connection settings programmatically in symfony (using Doctrine)?
Assuming you have the EntityManager as $this->em
Get Doctrine Database Name from Symfony2:
$this->em->getConnection()->getDatabase();
Get Doctrine Host Name (Server Name) from Symfony2:
$this->em->getConnection()->getHost();
There are many other parameters you can access from the connection such as username
, port
and password
. See the connection class for more info