Home > Backend Development > PHP Tutorial > Thinkphp实现MySQL读写分离操作示例_php实例

Thinkphp实现MySQL读写分离操作示例_php实例

WBOY
Release: 2016-05-17 08:40:36
Original
1073 people have browsed it

相对于其他方法实现MySQL的读写分离来说,采用Thinkphp框架实现MySQL的读写分离简单易用,其配置文件示例代码如下:

'DB_TYPE'=> 'mysql',
'DB_DEPLOY_TYPE' => 1, //开打支持多服务器        
'DB_RW_SEPARATE'=>true,//数据库读写否分离
'DB_HOST'=> '192.168.11.101,192.168.11.102', 
'DB_NAME'=>'test',      
'DB_USER'=>'admin',      
'DB_PWD'=>'admin101',    
'DB_PREFIX' => 'fav_',
Copy after login

注意事项:

1、当采用原生态的sql语句进行写入操作的时候,要用execute,读操作要用query
2、MySQL数据主从同步还是要靠MySQL的机制来实现,所以这个时候MySQL主从同步的延迟问题是需要优化,延迟时间太长不仅影响业务,还影响用户体验。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template