search

Home  >  Q&A  >  body text

doctrine2 - symfony2 I need to connect to 2 different databases. What should I do?

I need to obtain data from two databases in the controller, how to do it?
http://symfony.cn/docs/cookbook/doctrine/multiple_entity_managers.html...
I searched for this answer, but after doing it, it didn't work

巴扎黑巴扎黑2820 days ago464

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 16:46:17

    Get database A instance

    $emA = $this->get('doctrine')->getManager('default');
    

    Get data B instance

    $emB = $this->get('doctrine')->getManager('customer');
    

    Get data from the product entity of the A instance

    $productsA = $emA->getRepository('AppBundle:Product')->findAll();
    

    Get data from the product entity of the B instance

    $productsB = $emB->getRepository('AppBundle:Product')->findAll();
    

    reply
    0
  • Cancelreply