The so-called master-slave separation is written from the primary database, from the server to read data, whether a main one from or a master from, the server is instantaneous synchronization, the program end only need to process is written in the primary server write, read in from the server read.
First, thinkphp to achieve master-slave separation
thinkphp Support master-slave separation, configuration is also very easy
' Db_deploy_type ' => 0,//Database Deployment mode: 0 Centralized (single server), 1 distributed (Master-slave server)
' Db_rw_separate ' => false,//database read/write separate master-slave valid
' Db_host ' = ' 192.168.1.101,192.168.1.102 ',
' Db_user ' => ' user1,user2 ',
' Db_pwd ' => ' pwd1,pwd2 ',
The default first database 78 is the primary database, responsible for the write operation, the second 60 is responsible for reading, thinkphp will automatically recognize read and write, and then assign the link to the corresponding database, to achieve the effect of read and write separation.
Precautions:
1. If you are setting up a distributed database, DB_DSN configuration is not currently supported.
2. If you are currently using a distributed database and you have set up a read-write separation, the query method is always performed at the read server, so the query method corresponds to a read operation, regardless of what your SQL statement is.
3. If you are currently using a distributed database and you have set up a read-write separation, the Execute method is always executed at the write server, so the Execute method corresponds to the write operation, regardless of what your SQL statement is.
Therefore, ' db_dsn ' => ' Mysql:host=192.168.100.60;dbname=51fanli_cang ', this way does not support master-slave separation, need to change.
When using the original ecological SQL statement to write operations, to use Execute, read the operation to use query, remember, otherwise disorderly dropped.
Second, ecshop reading and writing separation
http://blog.csdn.net/very_loong/article/details/7999895