I'm new to Symfony2. And my question quite simple. I would use 2 connections to DB at different host and driver in one bundle.
Could you help me with this?
You can do something like:
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
You see, we declare two connections in the dbal
section and two entity managers in the orm
one.
After that, you can use both:
$emAlpha = $this->getDoctrine()->getEntityManager('alpha');
$emBeta = $this->getDoctrine()->getEntityManager('beta');
As the alpha
one was defined as the default one, you can access it without specifying its name:
$emAlpha = $this->getDoctrine()->getEntityManager();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With