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

Changing connection through Builder

In my project it is very hard to use models for making queries. So I.m trying to do it using Builder. But I need to make queries in 2 or 3 different databases. So how can I switch connection or set connection service through Builder or modelManager?



98.9k

Queries built with the QueryBuilder also use models since it internally builds a PHQL statement which eventually will request the read connection from the used models. You could better access the database connection directly from the DI:

$result = $this->db1->query('SELECT ...');
$result = $this->db2->query('SELECT ...');

Ok, thank you!