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

How to Excute sentence query complex mysql in phalcon

Hi, I have a sentence MYSQL

"update users set users.propertysites = case when users.propertysites = '' then ',41,42,' else CONCAT(users.propertysites, '41,42,') end where users.id in (211) "

I'm run it in model of phalcon:

$getSQL = "update MyApp\Model\Users users set users.propertysites = case when users.propertysites = '' then ',41,42,' else CONCAT(users.propertysites, '41,42,') end where users.id in (211) ";

$query = $this -> modelsManager -> createQuery($getSQL);

return $query -> execute();

I receve error: syntax CASE

Please help Excute sentence query complex mysql in phalcon. thanks

edited Apr '17

CASE is not well supported in PHQL, you should change it to if:

UPDATE Users SET propertysites = IF(propertysites = '', '41,42', CONCAT(propertysites,',41,42')) WHERE id IN (211)
edited Apr '17

The syntax for case in phql is like this:

CASE CONDITON
WHEN VALUE1 THEN
EXPRESSION1
WHEN VALUE2 THEN
EXPRESSION2
END