php-orm-pdo
php-orm-pdo copied to clipboard
How i can use master and slave database
I would say you can simply create 2 different classes and overwrite the connection part on each of them, and then inherit from the one that uses the connect you want?
Yes, @msoffredi. Thanks for your help.
I think that something like this should work:
MasterModel.php
use SimpleORM\core\model\Model;
class MasterModel extends Model
{
public $db_config = [
'db_host' => '192.168.1.1',
'db_name' => 'test',
'db_user' => 'root',
'db_pass' => ''
];
}
SlaveModel.php
use SimpleORM\core\model\Model;
class SlaveModel extends Model
{
public $db_config = [
'db_host' => '192.168.1.1',
'db_name' => 'test',
'db_user' => 'root',
'db_pass' => ''
];
}
And them you use with your own models:
use YourNamespace\AppModel;
class Example extends MasterModel
{
public $table = 't_user';
public $pk = 'user_id';
public function getAll()
{
return $this->findAll();
}
}
.....
Let me know if you need more help.