Compared to other methods to achieve MySQL's read and write separation, the use of thinkphp framework to achieve MySQL read and write separation is simple and easy-to-use, the configuration file sample code is as follows:
' Db_type ' => ' mysql ',
' Db_deploy_type ' => 1,//fight to support multiple server
' db_rw_separate ' =>true,//database read/write no separation
' db_ HOST ' => ' 192.168.11.101,192.168.11.102 ',
' db_name ' => ' test ',
' db_user ' => ' admin ',
' db_pwd ' = > ' admin101 ',
' db_prefix ' => ' fav_ ',
Precautions:
1, when the use of the original ecological SQL statements to write operations, to use execute, read operation to use Query.
2, MySQL data master-slave synchronization or rely on the mechanism of MySQL to achieve, so this time the MySQL master-slave synchronization problem is the need to optimize the delay time is too long not only affect the business, but also affect the user experience.