Doctrine Query to find total number of Result in MySQL with LIMIT Doctrine Query to find total number of Result in MySQL with LIMIT sql sql

Doctrine Query to find total number of Result in MySQL with LIMIT


There is a pagination feature, which is built-in in 2.2, and does something similar to what you're seeking:

https://www.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/pagination.html#pagination

But I do not believe it uses SQL_CALC_FOUND_ROWS: it does two (or three, depending on how you configure it) separate queries to get the results, and that is frequently the correct way to proceed.

If you really insist on using the MySQL feature, I think you need to use raw SQL and a result set mapping. Here's an example:

Count of rows in Doctrine 2


On a completely separate note, test whether SQL_CALC_FOUND_ROWS is actually worth using for your particular query. Count is well optimized in MySQL for queries like the one you're doing. See this question in particular:

Which is fastest? SELECT SQL_CALC_FOUND_ROWS FROM `table`, or SELECT COUNT(*)


You can get count by accessing to EntityPersister::count(array $criteria)

For example:

$count = $doctrineEntityManager        ->getUnitOfWork()        ->getEntityPersister(Entity::class)        ->count($criteria);


May be this can be help you

Doctrine::getTable('TableName')->createQuery('t')->where('Your Condition') ->execute() ->rowCount();

OR

Doctrine::getTable('TableName')->createQuery('t')->where('Your Condition') ->count();

I preferred SECOND ONE

You can do like this,

$q = Doctrine_Query::create()        ->select('ss.*')        ->from('SalarySurvey ss')        ->where('ss.user_id=?', $user_id)        ->groupBy('created_at')        ->execute();$totalData = $q->count();

For the LIMIT

$q = Doctrine_Query::create()        ->select('u.username, p.phonenumber')        ->from('User u')        ->leftJoin('u.Phonenumbers p')        ->limit(20);echo $q->getSqlQuery();

The Output of this query is like this ---

SELECT    u.id AS u__id,    u.username AS u__username,    p.id AS p__id,    p.phonenumber AS p__phonenumberFROM user u    LEFT JOIN phonenumber p        ON u.id = p.user_idLIMIT 20

For more details look at check here