我正在尝试使用BETWEEN的学说来获取数据
$qb = $this->createQueryBuilder("E")
->select("E.id,E.publicationStatus,E.isArchived,E.isCancelled")
->where("E.publicationPlannedFromDate BETWEEN CURRENT_TIMESTAMP() - INTERVAL 5 MINUTE `AND` CURRENT_TIMESTAMP()");
return $qb->getQuery()->getArrayResult();
但是他给了我错误
[Syntax Error] line 0, col 250: Error: Expected Doctrine\ORM\Query\Lexer::T_AND, got '5'
您可以使用自定义DQL custom user defined functions或仅查询构建器表达式方法。对于第二个查询,您可以按以下方式更改查询:
$qb->select("E.id, E.publicationStatus, E.isArchived, E.isCancelled")
->from('Entity', 'E')
->add("WHERE",
$qb->expr()->between(
"E.publicationPlannedFromDate",
"DATE_SUB(CURRENT_TIMESTAMP(), 5, 'MINUTE')",
"CURRENT_TIMESTAMP()"
)
);