Getting error while using interval in doctrine

痴心易碎 提交于 2019-12-12 18:56:29

问题


When I use below query (Doctrine 2), I was getting error, and can't use INTERVAL in query,

$qb->andWhere("(pv.appointment_date + INTERVAL 48 HOUR) >= UTC_TIMESTAMP()");

Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '48'"


回答1:


If you want to use INTERVAL (in Doctrine 2, DQL) on mysql comumn field, You can use as below,

$qb->andWhere("DATE_ADD(pv.appointmentDate,48,'hour') >= UTC_TIMESTAMP()");

It will print SQL as below,

...... DATE_ADD(p0_.appointmentDate, INTERVAL 48 HOUR) >= UTC_TIMESTAMP() .....



回答2:


Doctrine is an ORM which used DQL, it is not same as SQL. Not all functions in the sql are supported by doctine by default. DQL doesn't ships with the support for INTERVAL. For that you have to add user defined functions DQL User Defined Functions.

A complete set of function is available in this git repo DoctrineExtensions

And the above query will become DATE_ADD(pv.appointment_date, INTERVAL 48 HOUR) >= UTC_TIMESTAMP()



来源:https://stackoverflow.com/questions/55624934/getting-error-while-using-interval-in-doctrine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!