如何在 Symfony2 上自定义错误消息
我正在尝试使用 DQL 在 ManyToMany 关系之间创建查询,这里是我的代码片段:
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery("SELECT * FROM TestGroupBundle:Question");
这是一个非常基本的 SQL 行,但我总是收到这个奇怪的错误:
[Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | "(" Subselect ")" | ScalarExpression, got '*'
500 Internal Server Error - QueryException
有人可以告诉我什么吗这意味着请以及如何解决它?谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您混淆了 SQL 和 DQL。由于您正在使用对象模型,因此 DQL 中没有“*”。正确的语法是“SELECT q FROM TestGroupBundle:Question q”。结果包装在
\Doctrine\Common\Collections\ArrayCollection
对象中。您可以迭代该对象以获得结果。关于 DQL,需要记住一件重要的事情:
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\ArrayCollection
object. You can iterate over the object to get your results.There's one important thing to keep in mind about DQL:
Doctrine 并不总是正确解析命名空间快捷方式。尝试使用完整的命名空间而不是
TestGroupBundle:Question
Doctrine doesn't always parse namespace shortcuts correctly. Try using the full namespace instead of
TestGroupBundle:Question