在Symfony2中使用Doctrine DQL时检索的记录数量限制
16lz
2021-01-22
I have the following query:
我有以下查询:
$latestcontent = $em->createQuery('
SELECT c.title, c.content, c.lastedit, a.firstname, a.surname
FROM ShoutMainBundle:Content c, ShoutMainBundle:Admin a
WHERE c.author = a.id
ORDER BY c.lastedit ASC'
);
What I need to do, is limit the amount of records returned from this query. However, when I add LIMIT 10 to the SQL query, it returns this error:
我需要做的是限制这个查询返回的记录的数量。但是,当我在SQL查询中添加LIMIT 10时,它会返回这个错误:
Error: Expected end of string, got 'LIMIT'.
错误:期望结束字符串,得到'LIMIT'。
So, I had a look and found that you could do add ->limit(10)
to the code (after the query). But this then throws up this PHP error:
所以,我看了一下,发现可以对代码执行add ->limit(10)(查询之后)。但是这就抛出了PHP错误:
Fatal error: Call to undefined method Doctrine\ORM\Query::limit() in C:\wamp\www\src\Shout\AdminBundle\Controller\DefaultController.php on line 22
What am I doing wrong?
我做错了什么?
1 个解决方案
#1
54
There is no statement like LIMIT for DQL currently, as far as I know.
就我所知,目前还没有关于DQL的极限这样的语句。
You have to use Query::setMaxResults().
必须使用Query::setMaxResults()。
更多相关文章
- fgetcsv()错误地将双引号添加到第一行的第一个元素
- CakePHP错误:在Acl中找不到类'String'
- 如何捕获错误,如无法打开流和连接超时
- 错误1452:无法添加或更新子行:外键约束失败
- 将DOMDocument中的特定元素导出为字符串
- PHP实现字符串转换成查询语句
- mysql 判断null 和 空字符串
- Oracle相当于MySQL代码“插入虚拟”以返回错误消息
- MySQL添加外键错误1215