在 symfony 中查找当前 Doctrine 数据库连接设置 [英] Find current Doctrine database connection settings in symfony

查看:18
本文介绍了在 symfony 中查找当前 Doctrine 数据库连接设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)?

解决方案

for example:

foreach(Doctrine_Manager::getInstance()->getConnections() as $connection){
  $conn = $connection->getOptions();
  preg_match('/host=(.*);/', $conn['dsn'], $host);
  var_dump($host);
}

这篇关于在 symfony 中查找当前 Doctrine 数据库连接设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆