Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:39:10+00:00 2026-06-06T21:39:10+00:00

I have a Symfony2 project with a MySQL db: #app/config/config.yml doctrine: dbal: driver: %database_driver%

  • 0

I have a Symfony2 project with a MySQL db:

#app/config/config.yml
doctrine:
    dbal:
        driver:   %database_driver%    # <
        host:     %database_host%      # |
        port:     %database_port%      # | Defined in
        dbname:   %database_name%      # | parameters.ini
        user:     %database_user%      # |
        password: %database_password%  # <

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

Now I’d like to make simple queries (like routine calls) to an other database.

Should I define an other dbal into the config file ?
If yes, how can it be configured while keeping the default connection for the project ?
Do I have to configure an orm for each connection ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:39:12+00:00Added an answer on June 6, 2026 at 9:39 pm

    You need to add another level of configuration and also use multiple entity managers as Doctrine uses 1 entity manager per database connection .. your configuration might look something like this :

    doctrine:
        dbal:
          connections:
            default:
              driver:   %database_driver%    # <
              host:     %database_host%      # |
              port:     %database_port%      # | Defined in
              dbname:   %database_name%      # | parameters.ini
              user:     %database_user%      # |
              password: %database_password%  # <
            another:
              driver:   %database2_driver%    # <
              host:     %database2_host%      # |
              port:     %database2_port%      # | Defined in
              dbname:   %database2_name%      # | parameters.ini
              user:     %database2_user%      # |
              password: %database2_password%  # <
    

    Then you define your multiple entity managers as so

    doctrine:
        orm:
            default_entity_manager:   default
            entity_managers:
                default:
                    connection:       default
                    mappings:
                        AcmeDemoBundle: ~
                        AcmeStoreBundle: ~
                another:
                    connection:       another
                    mappings:
                        AcmeCustomerBundle: ~
    

    then in your action you can use the following to get the correct entity manager :

    $em = $this->get('doctrine')->getEntityManager('default');
    $em = $this->get('doctrine')->getEntityManager('another');
    

    depending on which entity manager you required

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I update my Symfony2 project I always have to do this: root@xxx:/var/www/project# php
I have a symfony project with the followin structure SDCU |-app |-----cache |-----logs |-bin
I have a regular class in my Symfony2 project: class RangeColumn extends Column{ //...
I have a join-table which is created by using @ORM\ManyToMany annotation in Symfony2/Doctrine. It
I have a Symfony2 project with its own database, and now I want to
I have a console app, (written as a Symfony2 command) that is reading input
I have a Symfony2 project under Debian. What are the steps to change my
I have a slow query in a Symfony2 project using Doctrine2. I am unsure
I have added the translator service for my Symfony2 project. I use it both
I have recently started setting up the security for my Symfony2 project. I opted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.