gpt4 book ai didi

php - 我将如何在 Doctrine2 中执行 MySQL 计数(*)?

转载 作者:IT老高 更新时间:2023-10-29 00:04:53 25 4
gpt4 key购买 nike

我有以下 Doctrine2 查询:

$qb = $em->createQueryBuilder()
->select('t.tag_text, COUNT(*) as num_tags')
->from('CompanyWebsiteBundle:Tag2Post', 't2p')
->innerJoin('t2p.tags', 't')
->groupBy('t.tag_text')
;
$tags = $qb->getQuery()->getResult();

运行时出现如下错误:

[Semantical Error] line 0, col 21 near '*) as num_tags': Error: '*' is not defined. 

我将如何在 Doctrine2 中执行 MySQL count(*)?

最佳答案

您应该能够像这样(将查询构建为字符串):

$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
$count = $query->getSingleScalarResult();

关于php - 我将如何在 Doctrine2 中执行 MySQL 计数(*)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12088026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com