We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Phalcon join multiple database in single query

Usually in SQL or Codeigniter's Active record we can join 2 different database tables in single query like:

  • join database_1.table_1 on ..
  • join database_2.table_2 on ..

How do we achieve this is "Phalcon"?

I tried to do it, but got an error:

  • SQLSTATE[42S02]: Base table or view not found:
  • 1146 Table 'database_2.table_2' doesn't exist


Hai; There is no problem at join tables in same database.

But my query is how do we JOIN tables in 2 different database? If i try to do it i get above error.

Please suggest some idea..

We have a client who has 2 databases. One is readonly and controlled by seperate software. The 2nd was created so we could add modules to the application with our own tables. Our tables need to join with the readonly tables from the first database. This is easy to do with raw sql:

FROM db1.employee
LEFT JOIN db2.user ON(db1.employee.empid = db2.user.empid)

But how can this be acomplishd with phalcon modle relationships ?