Skip to content
Advertisement

Error: Expected Literal, got ‘*’ in Doctrine

I want to retrieve the number of rows in my courrier table.

In my fixtures, I have these lines :

$query = $this->em->createQuery('SELECT count(*) FROM AppEntityCourrier');
$countCourrier = $query->getResult();

I have these mistakes when I do symfony console doctrine:fixtures:load :

In QueryException.php line 38:
                                                               
[Syntax Error] line 0, col 13: Error: Expected Literal, got '*'  
                                                               

In QueryException.php line 27:
                                        
SELECT count(*) FROM AppEntityCourrier  
                                       

What’s wrong with the * in my query ?

Advertisement

Answer

Doctrine expects you to use one of the fields of your entity. In SQL you don’t need to use count(*) to get the amount of rows count(id) also works as long as the column is not nullable.

So changing your query to SELECT count(c.id) FROM AppEntityCourrier as c should solve this.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement