How i can use Master-Slave?? I added 2 databases in services.php:
$di->setShared('db', function () {
$config = $this->getConfig();
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
$params = [
'host' => $config->database1->host,
'username' => $config->database1->username,
'password' => $config->database1->password,
'dbname' => $config->database1->dbname,
'charset' => $config->database1->charset
];
$connection = new $class($params);
return $connection;
});
$di->setShared('dbSlave', function () {
$config = $this->getConfig();
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
$params = [
'host' => $config->database2->host,
'username' => $config->database2->username,
'password' => $config->database2->password,
'dbname' => $config->database2->dbname,
'charset' => $config->database2->charset
];
$connection = new $class($params);
return $connection;
});
in model add next code:
public function initialize()
{
$this->setReadConnectionService('dbSlave');
$this->setWriteConnectionService('db');
}
why all my queries was executed only for 'db' connection?? and what i did wrong?? if possible, please give me a real working example, not a quote from the documents..thanks