Getting the total number of rows using SQL_CALC_FOUND_ROWS in a Zend table table

Is there a way to get the total number of rows in Zend db, for example using SQL_CALC_FOUND_ROWS in a regular mysql query. I could not find similar functionality for this, except to run the same request without the limit clause.

+3
source share
3 answers
$db->select()
   ->from($tableName, array(
       new Zend_Db_Expr('SQL_CALC_FOUND_ROWS id'), 
       'name', 
       'price'
   ));

You can also try replacing all cols with COUNT (*) and run the query a second time. It can actually be more effective (even if it runs counter to intuition). This was for my application.

You can do it as follows:

$select->reset('cols')->reset('limit')->cols('COUNT(*)'); //there is a constant for the 'cols' in Select class
$db->query($select);
+11
source

- , ZF. 2008 ZF, , .

+2

Use this method if you need data inside the rows.

   $rows = $db->select()->from('foo')->query()->fetchAll(); 

    echo 'Total number of rows found : ' . count($rows);

if you just need to calculate the total number of rows, then

$count = $db->select()->from('foo','COUNT(*)')->query()->fetchColumn();
0
source

Source: https://habr.com/ru/post/1771050/


All Articles