用户mySql和mongoDB一起在symfony2中

时间:2015-05-14 12:12:38

标签: mongodb symfony entity

据我所知,可以在symfony中设置第二个实体管理器。我也有可能将mysql用于特殊的Bundles mongodb吗?

我找到了一个如何在symfony中实现dbs的例子,但我不知道如何用mysql和mongodb一起处理它:

http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/config.html

2 个答案:

答案 0 :(得分:0)

是的,您可以在一个项目中使用这两个数据库驱动程序

doctrine:
    dbal:
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types:
                    enum: string
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

            dynamic:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types:
                    enum: string
                wrapper_class: 'My\DoctrineBundle\Connection\ConnectionWrapper'

你必须添加DoctrineBundle downlaoad并按照这个问题的答案定义上传到你的名字 Symfony connection wrapper

答案 1 :(得分:0)

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options: {}
    default_database: lead_base
    document_managers:
        default:
            auto_mapping: true