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 write this phalcon query ?

How write this Phalcon\Model query?

SELECT * FROM reset WHERE createdon < UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY )

Thanks.

This syntax is not supported because it's a MySQL extension that cannot be translated by PHQL when using PostgreSQL/SQlite/Oracle. You can use a raw sql query in this case: https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql

Another way is to using the MysqlExtended Dialect class: https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Db/Dialect

edited Nov '16

it works : )

$day = time()-86400;

$rs = Reset::find("createdon < $day");

It is bab practice to inject criteria params into PHQL. You have to use bind in order to allow PHQL engine use query cache:

$rs = Reset::find([
    'createdon > :day:',
    'bind' => [
        'day' => time() - 86400
    ]
]);

For more information see: https://docs.phalcon.io/en/latest/reference/models.html#binding-parameters