我是SF2的新手,我想知道如何管理几个数据库到ONE捆绑的连接.目前我有这个解决方案 - 工作正常 - 但我不知道这是否是正确的方法....
在myBundle\Ressource\config\config.yml中:
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: SERVER
user: root
password: null
host: localhost
client:
dbname: CLIENT_134
user: root
password: null
host: localhost
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
MyBundle: ~
client:
connection: client
mappings:
MyBundle: ~
Run Code Online (Sandbox Code Playgroud)
然后,为了切换到BD或其中一个,我做:
$O_ressource= $this->get('doctrine')->getEntityManager('client');
$O_ressource= $this->get('doctrine')->getEntityManager('default');
Run Code Online (Sandbox Code Playgroud)
那么伙计们,你认为这是管理这个的好方法吗?
我的第二个问题是:
如何设置动态数据库连接?我的意思是我的系统中有100个数据库,我无法在config.yml文件中设置它们.所以我希望能够动态更改数据库.
谢谢您的帮助!
symfony ×1