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

PHQL error

Hi everybody,

Below is PHQL query:

$phql = "select ar.reply_id,ar.artid,ar.reply_time,ar.second_reply,ar.reply_content,a.artname,c.cname from articlereply as ar ";
$phql .= "left join ( article as a left join category as c on a.cid=c.cid ) on ar.artid=a.artid ";
$phql .= "where ar.reply_uid=:reply_uid: order by ar.reply_time desc";

$article_reply = $this->modelsManager->executeQuery($phql,array(
    "reply_uid" => $reply_uid
));

i can use above sql running in mysql workbench,but cannot running in Phalcon,show below error:

PhalconException: Syntax error, unexpected token (, near to ' article as a left join category as c on a.cid=c.cid ) on ar.artid=a.artid where ar.reply_uid=:reply_uid: order by ar.reply_time desc', when parsing: select ar.reply_id,ar.artid,ar.reply_time,ar.second_reply,ar.reply_content,a.artname,c.cname from articlereply as ar left join ( article as a left join category as c on a.cid=c.cid ) on ar.artid=a.artid where ar.reply_uid=:reply_uid: order by ar.reply_time desc (261)



145.0k
Accepted
answer

God, why you are not using query builder ? left join ( article as a left join category as c on a.cid=c.cid ) what a hell is this join ? PHQL don't support syntax like this, just join category and then join article.

Hi ,

i have solved below PHQL query and new sql is below show:

$phql = "select ar.reply_id,ar.artid,ar.uid,ar.uname,ar.parent_id,ar.reply_uname,ar.reply_content,a.artname,c.cname from articlereply as ar "; $phql .= "left join article as a on a.artid=ar.artid "; $phql .= "left join category as c on c.cid=a.cid "; $phql .= "where ar.parent_id =:parent_id: order by ar.uname,ar.reply_time desc"; $articlereply = $this->modelsManager->executeQuery($phql,array( "parent_id" => $parent_id ));

God, why you are not using query builder ? left join ( article as a left join category as c on a.cid=c.cid ) what a hell is this join ? PHQL don't support syntax like this, just join category and then join article.

Use query builder pls, this looks really bad :)

Hi guy,

do you have the url about learning query builder ?thanks.

Use query builder pls, this looks really bad :)