当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Doctrine2 / Symfony2 - Using different databases per bundle

问题描述:

How can I use different databases in every single bundle of Symfony2 with Doctrine2?

FooBundle <- Database "Foo"

BarBundle <- Database "Bar"

网友答案:

This may help How to work with Multiple Entity Managers and Connections.

So you can define multiple Entity Managers related to your databases connections, you can then map your bundle(s) to the right Entity Manager.

The examples on the documentation are well explained.

doctrine:
    dbal:
        default_connection:   foo_connection
        connections:
            foo_connection:
                # ...
                # Foo connection parameters
                # ...
            bar_connection:
                # ...
                # Bar connection parameters
                # ...

    orm:
        default_entity_manager:   foo_manager
        entity_managers:
            foo_manager:
                connection:        foo_connection
                mappings:
                    FooBundle: ~
            bar_manager:
                connection:       bar_connection
                mappings:
                    BarBundle: ~
分享给朋友:
您可能感兴趣的文章:
随机阅读: