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!

Requirements

Base CDbConnection

Usage

Configure it as your system default db connection component.

'components'=>array(
	'db'=>array(
		'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
			array(
				'connectionString'=>'mysql:host=slave1;dbname=xxx',
				'username'=>'root',
				'password'=>'root'
			),
			array(
				'connectionString'=>'mysql:host=slave2;dbname=xxx',
				'username'=>'demo',
				'password'=>'xxx'
			),
		),
	),
)

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
23 followers
2 047 downloads
Yii Version: 1.1
License: MIT
Category: Database
Developed by: Jam
Created on: Dec 17, 2010
Last updated: 10 years ago

Downloads

show all