【问题标题】:Error: Expected Literal, got '*' in Doctrine错误:预期文字,在教义中得到“*”
【发布时间】:2021-11-05 09:23:06
【问题描述】:

我想检索我的快递表中的行数。

在我的固定装置中,我有以下几行:

$query = $this->em->createQuery('SELECT count(*) FROM App\Entity\Courrier');
$countCourrier = $query->getResult();

我在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 App\Entity\Courrier  
                                       

我的查询中的 * 有什么问题?

【问题讨论】:

    标签: php doctrine-orm doctrine dql


    【解决方案1】:

    Doctrine 希望您使用实体的其中一个字段。在 SQL 中,您不需要使用 count(*) 来获取行数 count(id) 也可以,只要该列不可为空。

    因此,将您的查询更改为 SELECT count(c.id) FROM App\Entity\Courrier as c 应该可以解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2015-04-08
      相关资源
      最近更新 更多