I’m trying to use DQL to create a query between a ManyToMany relation, here a snippet of my code:
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery("SELECT * FROM TestGroupBundle:Question");
It’s a really basic SQL line, but I always get this weird error:
[Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | "(" Subselect ")" | ScalarExpression, got '*'
500 Internal Server Error – QueryException
Can someone tell me what does it mean please and how to fix it ? Thanks
You’re mixing up SQL and DQL. There’s no “*” in DQL since you’re working with your object model. The proper syntax would be
"SELECT q FROM TestGroupBundle:Question q". The result is wrapped in\Doctrine\Common\Collections\ArrayCollectionobject. You can iterate over the object to get your results.There’s one important thing to keep in mind about DQL: