gpt4 book ai didi

php - 交响乐/主义 : Getting the first maximum value from database

转载 作者:行者123 更新时间:2023-11-29 11:34:42 25 4
gpt4 key购买 nike

我已经被困在这个问题上有一段时间了:

我想通过使用 DESC 对“datevalidite”列进行排序,从表“seuils”中提取值“points”。

SQL 工作正常:

SELECT points FROM seuils ORDER BY datevalidite DESC

但是我在 Symonfony Controller 中实现的代码返回了一个错误:

$dataSeuils = $this->getDoctrine()->getManager();
$seuils = $dataSeuils->createQuery(
'SELECT points
FROM AppBundle:Seuils
ORDER BY datevalidite DESC')->getResult();

这是错误消息:

[Syntax Error] line 0, col 53: Error: Expected end of string, got 'BY'

500 Internal Server Error - QueryException

1 linked Exception:

QueryException »

最后我需要提取返回的实体的属性点。

但我真的不明白为什么它在 phpMyAdmin(SQL)中可以正常工作,但在 Symfony 中却不能。

这是创建表的 SQL 代码片段:

CREATE TABLE `seuils` (
`points` int(11) NOT NULL,
`datevalidite` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

最佳答案

您可以使用存储库:

$dataSeuils = $this->getDoctrine()->getRepository('AppBundle:Seuils');

$seuils = $dataSeuils->createQueryBuilder('points')->orderBy('points.datevalidite', 'DESC')->getQuery()->getResult();

关于php - 交响乐/主义 : Getting the first maximum value from database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817806/

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