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)?
相关问题
- Symfony2 Set Controller in the kernelControllerEve
- Webpack Encore: cannot import local dependencies
- Render custom attribute KNP Menu
- Problems with cap deploy a symfony2 project, can
- Allow CORS on symfony 4
相关文章
- Symfony : Doctrine data fixture : how to handle la
- Symfony is linked to the wrong PHP version
- Symfony2: check whether session exists or not
- Is there a way to modify the entity mapping config
- symfony2 form choice and mongodb
- Symfony 3.1 and OneUpUploaderBundle + Blueimp = Up
- Symfony does not remove entity from collection
- Symfony: Inject object (not service) to service co
The dbname in the dsn for a specific conexion:
databases.yml
In the Action:
Then, the dbname is:
for example:
Try this one
Updated
As
Function split() is deprecated
so here is recommended way.Use this code:
Assuming you have the EntityManager as
$this->em
Get Doctrine Database Name from Symfony2:
Get Doctrine Host Name (Server Name) from Symfony2:
There are many other parameters you can access from the connection such as
username
,port
andpassword
. See the connection class for more info