原则DQL在查询生成器上引发致命错误

时间:2018-12-20 16:39:14

标签: doctrine-orm pagination

我遵循《学说》中的分页示例,但遇到致命错误:

PHP Fatal error:  Uncaught Doctrine\ORM\Query\QueryException: SELECT * FROM Model\Report r in /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43
Stack trace:
#0 /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(456): Doctrine\ORM\Query\QueryException::dqlError('SELECT * FROM M...')
#1 /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(2253): Doctrine\ORM\Query\Parser->syntaxError('IdentificationV...', Array)
#2 /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1182): Doctrine\ORM\Query\Parser->SelectExpression()
#3 /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(878): Doctrine\ORM\Query\Parser->SelectClause()
#4 /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(847): Doctrine\ORM\Query\Parser->SelectStatement()
#5 /usr/share/nginx/html/td/ven in /usr/share/nginx/html/td/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php on line 54

这是教义的默认示例 https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/pagination.html

这是我的代码:

<?php
use Doctrine\ORM\Tools\Pagination\Paginator;
require "bootstrap.php";

$dql = 'SELECT * FROM reports';

$max = isset($args[1])?$args[1]:5;

$query = $entityManager->createQuery($dql)->setFirstResult(0)->setMaxResults($max);

$paginator = new Paginator($query, $fetchJoinCollection = false);

$c = count($paginator);

foreach($paginator as $report){
    echo $report->getName() . "\n";
}

1 个答案:

答案 0 :(得分:1)

dql 选择中没有通配符*

更改

$dql = 'SELECT * FROM reports';

$dql = 'SELECT r FROM Model\Report r';

参考