title: Multiple, dynamic database connections in Symfony2
body: <p>I have a Symfony2 application that I want to make multi-tenant by the use of one database pr tenant (some don't consider this to be multi-tenancy, but that's not really the point).</p>
  
  <p>The <a href="http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html" rel="noreferrer">documentation</a> describes how to accomplish this. However, I want to be able to create tenants dynamically, and writing the new database connection details (and entity managers) to the config.yml file directly seems messy. I would rather have a separate database which holds the tenants and their connections, and then select the proper connection/em based on an identifier (fetched, for instance, from a the subdomain of the app - clientname.app.com).</p>
  
  <p>Using <a href="https://github.com/FriendsOfSymfony/FOSUserBundle/issues/413#issuecomment-10295345" rel="noreferrer">this approach</a> I should be able to accomplish this, but will at the same time probably break the ability to specify the database connection and/or entity manager when running the command line commands for updating database schemas and the likes.</p>
  
  <p>Provided that what I want to do make sense, is there a clever way to achieve this?</p>