如何在 CodeIgniter 中分离读取和写入以避免复制滞后?
How do I separate reads and writes in CodeIgniter to avoid replication lag?
我正在尝试让我们的应用程序的某些部分从只读数据库中读取,但我不想从每个模型中控制它,而是在全局级别上进行控制。
如何在 CodeIgniter 中分离读取和写入以避免复制滞后?
谢谢!
根据 CodeIgniter Documentation,您可以使用
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
连接到多个数据库。
要使用不同的数据库,您必须使用
$DB1->query();
$DB1->result();
代替
$this->db->query();
$this->db->result();
这个例子也摘自文档。
我正在尝试让我们的应用程序的某些部分从只读数据库中读取,但我不想从每个模型中控制它,而是在全局级别上进行控制。
如何在 CodeIgniter 中分离读取和写入以避免复制滞后?
谢谢!
根据 CodeIgniter Documentation,您可以使用
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
连接到多个数据库。 要使用不同的数据库,您必须使用
$DB1->query();
$DB1->result();
代替
$this->db->query();
$this->db->result();
这个例子也摘自文档。