We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problem with multiple database phalcon version 1.2.4

Ok, this is the situation

  • 1 server on address 10.10.1.4, with database db1 (master server)
  • 1 server on address 10.10.1.5, with database db1 (slave server)
  • 1 server on address 10.10.1.6 with database db2 (master server)
  • 1 server on address 10.10.1.6 with database db2 (slave server)

Ok, the conection at the database it's fine and working, but if i have:

$user1 = new models\db1\Usuario();
$userMaster = $user->find('username = 'asdf'');
$user2 = new models\db2\Usuario();
$userSlave = $user->find('login = 'asdf'');

I got the following error:

Se ha capturado un error. exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db1.master_user' doesn't exist' in /var/www/pil/app/library/Autenticador.php:125

Ok, my Usuario class:

--models/db1/Usuario.php

namespace models\db1

class Usuario extends \Phalcon\Mvc\Model{
    public function initialize(){
        $this->setReadConnectionService('slaveAdapter_db1');
        $this->setWriteConnectionService('masterAdapter_db1');
        $this->setSource('usuario');
    }
}

--- models/db2/Usuario.php

namespace models\db2

class Usuario extends \Phalcon\Mvc\Model{
    public function initialize(){
        $this->setReadConnectionService('slaveAdapter_db2');
        $this->setWriteConnectionService('masterAdapter_db2');
        $this->setSource('master_user');
    }
}

I do the following, thinking if the variables can't coexist in the same code block

class HiperClass
{
public function f1(){
   $user = new models\db1\Usuario();
   $user1 = $user->find('username = "asdf"');
}

public function f2(){
   $user = new models\db2\Usuario();
   $user2 = $user->find('login = 'asdf'');
}

public function f3(){
    $this->f1();
    $this->f2();
}

But it's the same problem, maybe it's for the conection isn't close, but my ideas it's running low.

Please anyone can help me.

thx

ps: sorry for my bad english, i hope that understood.

It's resolve. The problem isn't in the code with Phalcon, the problem is in another side of my application, in particular in the database connection. The rest of the code is correct