note 83586 modified in function.PDOStatement-rowCount by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:38:12 +0000 |
| Subject: | note 83586 modified in function.PDOStatement-rowCount by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147223@lists.php.net to get a copy of this message | ||
It'd better to use SQL_CALC_FOUND_ROWS, if you only use MySQL. It has many advantages as you
could retrieve only part of result set (via LIMIT) but still get the total row count.
code:
<?php
$db = new PDO(DSN...);
$db->setAttribute(array(PDO::MYSQL_USE_BUFFERED_QUERY=>TRUE));
$rs = $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM table LIMIT 5,15');
$rs1 = $db->query('SELECT FOUND_ROWS()');
$rowCount = (int) $rs1->fetchColumn();
?>
--was--
It'd better to use SQL_CALC_FOUND_ROWS, if you only use MySQL. It has many advantages as you
could retrieve only part of result set (via LIMIT) but still get the total row count.
code:
<?php
$db = new PDO(DSN...);
$db->setAttribute(array(PDO::MYSQL_USE_BUFFERED_QUERY=>TRUE));
$rs = $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM table LIMIT 5,15');
$rs1 = $db->query('SELECT FOUND_ROWS()');
$rowCount = (int) $rs1->fetchColumn();
?>
http://php.net/manual/en/function.PDOStatement-rowCount.php