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

Is it a bug of Phql ?

The query occurs a error below code, it is a bug of Phalcon?
Why is wrong? Thanks.

$money = '111';
$phql = 'update User set money = :money: + money WHERE id = 17';
$result = $this->modelsManager->executeQuery($phql,[
   'money' => $money
]);

This is the error message:

PDOException: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters


58.4k

I think you wrong, should be look like :)

$money = '111';
$phql = 'update User set money = :money:  WHERE id = 17';
$result = $this->modelsManager->executeQuery($phql,[
   'money' => $money + $money
]);


1.5k
edited Nov '14

Thank you. But it is not the result I want, I want to add 111 to the value of the original Like this SQL :

update user set money = money + 111 where id = 17

This is right. I would update column value in this way, but in phql it is wrong.

I think you wrong, should be look like :)

I don't know if there is any difference in using another type of placeholder but maybe you can try

$money = '111';
$phql = 'update User set money = ?0 + money WHERE id = 17';
$result = $this->modelsManager->executeQuery($phql,[
   0 => $money
]);

This isn't really trivial - but try turning on query logging, then check your query log after this query is run. That error happens when you mix ":money:" type parameters and "?0" type parameters. Since your query only has the former, I'm guessing somewhere in the parsing chain, the later format gets put in. Checking the query log should show you exactly what query is being sent to MySQL and causing the error.