Laureta Xhaferraj
Laureta Xhaferraj

Reputation: 63

Doctrine connection with db

I am about to start a project in doctrine symfony, but I have to make connection with multiple databases. One of them is an existing database (SQL SERVER) that cannot be mapped with ORM. Is there any possibility to connect with this db with another db that is NOT mapped in doctrine and work with controllers normally?

Upvotes: 3

Views: 1407

Answers (1)

Matteo
Matteo

Reputation: 39380

I develop a multi-database sf2 app with doctrine2 orm mapping.

We use intellectsoft-uk/MssqlBundle

Our configuration is:

config.yml

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: acme_mysql
        connections:
            acme_mysql:
                host: %acme_mysql_database_host%
                port: %acme_mysql_database_port%
                dbname: %acme_mysql_database_name%
                user: %acme_mysql_database_user%
                password: %acme_mysql_database_password%
                charset:  UTF8
            acme_slqsrv:
                driver:         sqlsrv
                driver_class:   \Realestate\MssqlBundle\Driver\PDODblib\Driver
                host: %acme_slqsrv%
                port: %acme_slqsrv%
                dbname: %acme_slqsrv%
                user: %acme_slqsrv%
                password: %acme_slqsrv%
                charset:  UTF8
orm: #optional if you want to map some entity in doctrine2
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: acme_mysql
    entity_managers:
        em_mysql:
            connection: acme_mysql
            mappings:
                AcmeMysqlBundle: ~
        em_sqlsrv:
            connection: acme_sqlsrv
            mappings:
                AcmeSqlSrvBundle: ~

This configuration permit you to take a connection instance in a controller/service and use it for access database and execute stored procedures and so on...

Hope this help

Upvotes: 2

Related Questions