gpt4 book ai didi

symfony - INTERVAL 1 MONTH 不使用 symfony2 Doctrine ?

转载 作者:行者123 更新时间:2023-12-03 21:30:55 24 4
gpt4 key购买 nike

我被困在这里,我花了最后 2 天解决这个问题,但失败了。我正在我的存储库中编写一个查询以获取当月的条目。这是我的查询:-

$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)')

当我尝试运行它时,它给了我一个错误
[Syntax Error] line 0, col 133: Error: Expected Doctrine\ORM\Query\Lexer::T_COMMA, got '1'

甚至我试过 this thing但没有帮助我。

最佳答案

您应该使用参数绑定(bind):

$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'));

关于symfony - INTERVAL 1 MONTH 不使用 symfony2 Doctrine ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10041513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com