ytdm
ytdm

Reputation: 1169

Doctrine DQL throws fatal error on query builder

I follow pagination example from Doctrine but get fatal error:

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

Here is the default example from Doctrine https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/pagination.html

and here is my code:

<?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";
}

Upvotes: 0

Views: 614

Answers (1)

Jannes Botis
Jannes Botis

Reputation: 11242

There is no wildcard * in dql select.

Change

$dql = 'SELECT * FROM reports';

to

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

References

Upvotes: 1

Related Questions