note 83586 modified in pdostatement.rowcount.php by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 21:14:54 +0000 |
| Subject: | note 83586 modified in pdostatement.rowcount.php by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147227@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/pdostatement.rowcount.php.php