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

标签 php mysql symfony doctrine-orm

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

我想通过使用 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/

相关文章:

php 停止包含文件,同时在实际文件中继续循环?

php - 多文件上传 PHP

javascript - Laravel Mix (webpack) Inline JS undefined jQuery/vendor

php - 如何在过程内部查询中使用过程参数变量

mysql - 将简单的元数据附加到 MySQL 数据库

Symfony 4 Voters - 角色和权限问题

php - 什么使 openssl_random_pseudo_bytes "cryptographically secure"?

symfony - Symfony2 路由中的两个可选变量

html - 如何设置 symfony2 表单按钮的样式

php - 使用 php 从 mysql 数据库中读取 blob