我是 Symfony2 的新手。我的问题很简单。
我会在一个捆绑包中使用不同主机和驱动程序上的 2 个与数据库的连接。
你能帮我解决这个问题吗?
你可以这样做:
doctrine:
dbal:
default_connection: alpha
connections:
alpha:
driver: pdo_mysql
host: localhost
dbname: alpha
user: root
charset: UTF8
beta:
driver: pdo_pgsql
host: localhost
dbname: beta
user: root
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
alpha:
connection: alpha
beta:
connection: beta
你看,我们在dbal
部分和两个实体经理orm
one.
之后,您可以同时使用:
$emAlpha = $this->getDoctrine()->getEntityManager('alpha');
$emBeta = $this->getDoctrine()->getEntityManager('beta');
As the alpha
一个被定义为默认的,您可以在不指定名称的情况下访问它:
$emAlpha = $this->getDoctrine()->getEntityManager();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)