且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:预期的已知函数,得到“GROUP_CONCAT"

更新时间:2022-05-18 08:29:35

GROUP_CONCAT 不是 DQL 函数.你不能在 DQL 中使用 MySQL 函数.以下是 Doctrine 在 DQL 中支持的函数列表:https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/dql-doctrine-query-language.html#dql-functions

GROUP_CONCAT is not DQL function. You can`t use MySQL functions in DQL. Here is a list of functions that Doctrine supports in DQL: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/dql-doctrine-query-language.html#dql-functions

我强烈建议您不要在您的应用中使用 GROUP_CONCAT.您可以在单独的查询中以数组的形式获取数据,并在 PHP 中将其连接起来.应该没有明显的性能开销.

但如果您真的必须使用它,您必须编写自己的用户定义的 DQL 函数.这是它的教程:https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/dql-user-defined-functions.html

But if you really have to use it you must write your own user defined DQL function. Here is tutorial for it: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/dql-user-defined-functions.html

以下是在 Symfony 中注册 DQL 函数的方法:https://symfony.com/doc/current/doctrine/custom_dql_functions.html

And here is how you register that DQL function inside Symfony: https://symfony.com/doc/current/doctrine/custom_dql_functions.html