INTERVAL 1 MONTH 不使用 symfony2 原则? [英] INTERVAL 1 MONTH not working With symfony2 doctrine?
本文介绍了INTERVAL 1 MONTH 不使用 symfony2 原则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被困在这里,我花了最后 2 天解决这个问题,但失败了.我正在我的存储库中编写一个查询以获取当月的条目.这是我的查询:-
I am stuck here and i spend last 2 days resolving this issue but failed. I am writing a query inside my repository to get the entries for current month. here is my query:-
$this->getEntityManager()
->createQuery('SELECT count(a) FROM CollegeStudentBundle:StudentAttendance a where a.student_id='.$id.'
and a.date > DATE_SUB(CURRENT_TIMESTAMP(),INTERVAL 1 MONTH)')
当我尝试运行它时,它给了我一个错误
When I try to run this it gives me an error
[Syntax Error] line 0, col 133: Error: Expected DoctrineORMQueryLexer::T_COMMA, got '1'
即使我尝试过 这件事但对我没有帮助.
Even I tried this thing but didn't helped me.
推荐答案
你应该使用参数绑定:
$query = $em->createQuery('SELECT count(a) FROM CollegeStudentBundle:StudentAttendance a where a.student_id = :id and a.date > :date');
$query->setParameter('id', $id);
$query->setParameter('date', new DateTime('-1 month'));
这篇关于INTERVAL 1 MONTH 不使用 symfony2 原则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文