dbreadwritesplitting Database read write operation use splitting connection.Read from slave database,write to master database.

  1. Requirements
  2. Usage

A very simple component that allow you to use master/slave splitting database connection.That read operation will route to slave db,write operation will route to master db.

Notice:You need config your mysql database server to synchronize bettween master/slave,this component doesn't finish the data synchronize job!


Base CDbConnection


Configure it as your system default db connection component.

		'class'=>'DbConnectionMan',//Specify it,instead of CDbConnection,other options is same as CDbConnection
		'connectionString' => 'mysql:host=localhost;dbname=test',
		'emulatePrepare' => true,
		'username' => 'root',
		'password' => 'root',
		'charset' => 'utf8',
		'enableSlave'=>true,//Read write splitting function is swithable.You can specify this value to false to disable it.
		'slaves'=>array(//slave connection config is same as CDbConnection

Update 2012-10-08:

Support slave db random choices.

Fixed:createCommand accept null parameter;

Improved:isReadOperation no longer use preg_match

Update 2013-07-15:

Fixed: Tolerate master db in a dead state.

Update 2013-09-13: Fixed: Mark master db dead bug.

Improvement: When one slave or master db down,it will mark this server dead for 10 minutes in memcache.So it will not try again connect to dead server untill 10 minutes elapsed.

My Blog:jex.im

11 0
2 047 downloads
Yii Version: 1.1
License: MIT
Category: Database
Developed by: Jam
Created on: Dec 17, 2010
Last updated: 9 years ago


show all