[Symfony2] About DB Master/Slave Configuration

Tadashi Shigeoka ·  Mon, February 6, 2012

I looked up DB Master/Slave configuration in Symfony2, so taking notes.

While symfony1 series has sfDoctrineMasterSlavePlugin, I was wondering if there was something similar for Symfony2, and there was.

It seems you can do it using MasterSlaveConnection implemented from Doctrine’s DBAL2.16.

lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php at master from doctrine/dbal - GitHub  

If you can’t use DBAL2.16 or later, it seems you’ll have to handle it by “explicitly switching EntityManager for each database connection” by referring to the following articles.

Symfony2を利用してのDBのMaster/Slave構成について - Google グループ

複数のエンティティマネージャと連携する方法 | Symfony2日本語ドキュメント

That’s all from the Gemba regarding Symfony2 database master/slave configuration.