CodeIgniter configure different IP for READ and WR

2019-07-18 23:43发布

My company has been setting up a different server for read and write access of mysql DB. Previously, we use custom php script. However, I was recently given task to create tools by leveraging CI. I've done it on test server. Now, I'm confused, how to implement it on live server.

3条回答
Animai°情兽
2楼-- · 2019-07-19 00:13

I've made a simple libary that extend database functionality. You can modify it depend with what you need. http://rangga.net/splitting-read-write-codeigniter-database/

查看更多
Emotional °昔
3楼-- · 2019-07-19 00:18

Setup multiple 'connection groups' for each server in your database.php config file, then in the Model:

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

//read from DB1
$DB1->query();

//write to DB2
$DB2->insert();

See examples in: Connecting to Multiple Databases

查看更多
不美不萌又怎样
4楼-- · 2019-07-19 00:20

Might it be easier, rather than doing this by IP, do it using MySQL users.

You could have two different users, one with all the write privileges like INSERT and UPDATE, then another user with all the READ privileges like SELECT, or what ever you wish.

Then what ever code is running on your write web server uses the write user and vice-a-versa?

查看更多
登录 后发表回答