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

Connect to database server

Is it posiible to connect to database server, without creating a multiple databases connections in phalcon, without using an external libs?

        $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(
            [
                'host'     => 'localhost',
                'username' => 'user',
                'password' => 'pass',
                //'dbname'   => 'database1',
                'port'     => 3306,

            ]
        );
class SomeModel extends Model
{
    // ....
    /**
     * Set the table source.
     *
     * @return string
     */
    public function getSource()
    {
        return 'database1.some';
    }
}
class OtherModel extends Model
{
    // ....
    /**
     * Set the table source.
     *
     * @return string
     */
    public function getSource()
    {
        return 'database2.other';
    }
}


1.9k

I think that PDO don't allow that



85.5k
Accepted
answer

you can try with multi module app. In module.php you can specify the db connection.

If it works for you

Ok, will do it with multi modules, tnx