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 update

Hi,

I have some problems when using PHQL, do you have any idea? FYI, I do not use any Constraints in both MySQL and Phalcon.

thanks in advance

<?php

$query = 'UPDATE Table SET column = "value" WHERE id IN (1,2,3,4,5)'; // work
$query = 'UPDATE Table SET column = "value" WHERE id > 0';            // nothing happen in database
$query = 'UPDATE Table SET column = "value" WHERE 1';                 // nothing happen in database
$query = 'UPDATE Table SET id = 100 WHERE id = 101';                  // nothing happen in database
$query = 'UPDATE Table SET column = "value" WHERE id IN (1,2,3,4,5) ORDER BY id'; // error: "Syntax error, unexpected token ORDER, near to ' BY id', when parsing: UPDATE Table SET column = "value" WHERE id IN (1,2,3,4,5) ORDER BY id"
$this->modelsManager->executeQuery($query);

update:

I do more tests, and the result is showing that if I'm updating more than 7 rows it will not work.


update:

I still haven't found the solution to make PHQL works in this particular case. I tried raw SQL with the way provided by Andrey at https://forum.phalcon.io/discussion/734/update-table-in-raw-sql-returning-value-on-success, now it works. More info, if update with the way described in doc: https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql, it will give "SQLSTATE[HY000]: General error" error.



1.3k

is the model for Table already created ?



25.7k

Hi xicond,

Thanks for your reply, I truly appreciate it. Yes the corresponding model is created and working fine.

is the model for Table already created ?



1.3k

need to investigate the model Table I think the "Syntax error, unexpected token ORDER" is already right



25.7k

Do you mean my model file cause the problem?

need to investigate the model Table I think the "Syntax error, unexpected token ORDER" is already right



1.3k

Maybe, cause sometimes it bugs my code



25.7k

Actually it is possible, I did look at the model file and it looks ok to me.

Maybe, cause sometimes it bugs my code