Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How i can use master and slave database #5

Open
sandeep-nambiar opened this issue Oct 15, 2018 · 2 comments
Open

How i can use master and slave database #5

sandeep-nambiar opened this issue Oct 15, 2018 · 2 comments
Labels

Comments

@sandeep-nambiar
Copy link

No description provided.

@msoffredi
Copy link

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?

@arojunior
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants