I have been building a new platform for an existing product over the past year. It so happens that we are using the CakePHP framework (version 2.2.1 as of this writing). The database connection requirements are designed to distribute the load of database access across multiple instances. The idea is we will setup a MySQL master / slave combination. All of the inserts, updates, and deletes will be performed on the master database. All of the selects will be sent to the slave database.
As I thought about this in more depth, I wasn’t quite sure how I would accomplish this. I first thought about using the beforeFind and beforeSave callbacks in the AppModel.php. I would set the $this->useDbConfig to readOnly or writeOnly and viola, instant database changing! WRONG! It didn’t work. Why? Because the $this->useDbConfig is used to bind a model to a database. It’s a one-to-one relationship model-to-database. It didn’t always work trying to switch between the two using this method. Continue reading


Through the years, I have realized there are two types of web applications.