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

Set Connection in QueryBuilder

Hi,

Today I work with 3 databases (AWS RDS instances: 1 master and 2 replics to reader). I know i can set in model what connection use, and by my tests if i use funcion query he uses the connection setted in "initialize" my doubt is if i can define in a expecifique QueryBuilder (Phalcon\Mvc\Model\Query\Builder) which of 3 databses use?

How is the best way to do this with Phalcon?

edited Aug '17

The query builder is responsible for creating the SQL code only. It doesn't make a connection to the database.

https://docs.phalcon.io/en/latest/db-models#setting-multiple-databases

(the anchor doesn't appear to work, but scroll down!)

Correct anchor: https://docs.phalcon.io/en/latest/db-models#multiple-databases

The query builder is responsible for creating the SQL code only. It doesn't make a connection to the database.

https://docs.phalcon.io/en/latest/db-models#setting-multiple-databases

(the anchor doesn't appear to work, but scroll down!)