Symfony2 &Doctrine - 获取从数据源返回的行数 [英] Symfony2 & Doctrine - Get number of rows returned from datasource

查看:17
本文介绍了Symfony2 &Doctrine - 获取从数据源返回的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Symfony2 存储库类中有以下代码...

I have the following code in my Symfony2 Repository Class...

$query = $this->createQueryBuilder('foo')
        ->where('foo.bar = :id')
        ->setParameter('id', $myID)
        ->getQuery();

如何获取数据库找到的行数?

How do I get the number of rows found by the database?

提前致谢

推荐答案

你需要执行 DQL 来做你想做的事情.

You need to execute DQL to do something you want.

$query = $this->createQueryBuilder()
              ->from('foo', 'f')
              ->where('foo.bar = :id')
              ->setParameter('id', $myID)
              ->getQuery();


$total = $query->select('COUNT(f)')
               ->getQuery()
               ->getSingleScalarResult();

这篇关于Symfony2 &Doctrine - 获取从数据源返回的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆