catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Can we support the master-slave mode? #608

Closed anyforever closed 3 years ago

anyforever commented 7 years ago

Can we support the master-slave mode?

Andrews54757 commented 7 years ago

@anyforever Like this? https://gist.github.com/kookxiang/9f24b756122ec03c1511

I dont think you can acheive sql replication with just php

anyforever commented 7 years ago

@Andrews54757 yes. select from slave, insert/update/delete/... from master

Andrews54757 commented 7 years ago

Wouldnt having multiple medoo instances also work?

Andrews54757 commented 7 years ago

@anyforever Or you can create a helper class

use Medoo\Medoo;

class Manager {
         public $MASTER;
         public $SLAVE;
         __construct($opt1,$opt2) {
                  $this->MASTER = new Medoo($opt1);
                  $this->SLAVE = new Medoo($opt2);
         }
         select($table, $join, $columns = null, $where = null) {
                  $this->SLAVE->select($table, $join, $columns, $where);
         }
         insert($table, $datas) {
                  $this->MASTER->insert($table, $datas);
         }
         update($table, $data, $where = null) {
                  $this->MASTER->update($table, $data, $where);
         }
         delete($table, $where) {
                  $this->MASTER->delete($table, $where);
         }
         replace($table, $columns, $where = null) {
                  $this->MASTER->replace($table, $columns, $where);
         }
}

Dont see why any editing has to be done with medoo. I think its fine.

anyforever commented 7 years ago

@Andrews54757 I'll try it. Thanks.

Andrews54757 commented 7 years ago

Glad I could help.