Search code examples
mysqlzend-frameworkzend-dbamazon-rds

Zend Framework and mysql slaves support


I'm looking for a generic way on managing database connections in Zend Framework (1.1).

Our ZF application is hosted in the amazon cloud and we use their RDS solution. Adding the read replica servers is easy, however we would like to add support for it in our application. We're looking for the best & easy solution for handling it. Any suggestions would be great.

I know how to switch between database connections in Zend_Db_Select and in Zend_Db_Tables, but I'm looking for a more centralized and automatic framework as much as possible, so we won't need to set up the slave support in each query / model.

I also read about mysql proxy, but I rather not introduce another software layer in our application.


Solution

  • Are you really using ZF 1.1? Or ZF 1.10/1.11? In the latter case, you can use Zend_Application_Resource_Multidb to setup different database resources.

    If you need to switch automatically (load balancing) there are many ways. I dont know about LoadBalancers for MySQL but programmatically, you can switch the default adapter randomly in your bootstrapping to one of the multidbs. Then your application uses per request a random database (if you use Zend_Db_Table::getDefaultAdapter() / Zend_Db_Table::getAdapter())

    Or you create a own proxy class which manage this for you. More infos about your environment and your exact use-cases could be useful.