Nick S.
Nick S.

Reputation: 353

Using two databases at the same time with Symfony2

I am currently rebuilding a back-end CMS/CRM/user management system for our front-facing website. Historically, the databases for the two systems have been combined into one, huge, sloppy database (for example CRM data and user data are two separate tables). All of the tables on the website itself, and the back-end system, interface with each other (ie. I can create new users with the back-end system OR register on the website itself).

Now, as I mentioned, I'm rebuilding the system using Symfony2. I'm migrating it to a separate webserver (security, etc.) and therefore migrating it's portion of the DB to its own database. However, I'd still like for it to interact with the website's database.

Is there a relatively simple method in Symfony to make this kind of connection, or does everything need to be hosted in the same database?

Upvotes: 1

Views: 90

Answers (1)

ScayTrase
ScayTrase

Reputation: 1830

CookBook Says you can set up several connections as managers.

Than you can call it as following from the controller

    // both return the "default" em
    $em = $this->get('doctrine')->getManager();
    $em = $this->get('doctrine')->getManager('default');

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

Upvotes: 4

Related Questions