INTERVAL 1个月不工作与symfony2教义? [英] INTERVAL 1 MONTH not working With symfony2 doctrine?
本文介绍了INTERVAL 1个月不工作与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 Doctrine\ORM\Query\Lexer::T_COMMA, got '1'
即使我尝试了,但没有帮助我。
Even I tried this thing but didn't helped me.
推荐答案
您应该使用参数绑定:
You should use parameter binding:
$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个月不工作与symfony2教义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文