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

Inner Join in PHQL

Hello everybody,

I want to use this SQL Query :

SELECT DISTINCT name,picture FROM Bar AS b INNER JOIN Beer AS be ON b.id = be.idBar AND be.day = :day;

in my application :

$bars = $app->modelsManager->executeQuery($phql, array( 'day' => $day ));

But I get this error:

Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'Syntax error, unexpected token COLON, near to 'day;', when parsing: SELECT DISTINCT name,picture FROM Bar AS b INNER JOIN Beer AS be ON b.id = be.idBar AND be.day = :day;

Does anybody has an idea what the problem could be?

Bruno

Placeholders in PHQL require two colons:

$phql = "SELECT DISTINCT name,picture FROM Bar AS b INNER JOIN Beer AS be ON b.id = be.idBar AND be.day = :day:";

If you want to use plain SQL queries, you can use Phalcon\Db: https://docs.phalcon.io/en/latest/reference/db.html#finding-rows



6.3k

Thank You