I am about to use Zend_Paginator class in my project. I found examples of the class on the internet. One of them is
$sql = 'SELECT * FROM table_name ';
$result = $db->fetchAll($sql);
$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(10));
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;
on the first line, it actually select all the rows from table_name. What if I have a table with 50000 rows? That would be very inefficient.
Is there any other way to use Zend Paginator?
About this problem, you might be interested by this section of the manual : 39.2.2. The DbSelect and DbTableSelect adapter, which states (quoting, emphasis mine) :
(There is more to read on that page — and there is an example that should give you more information)
The idea is that you will not fetch all data yourself anymore, but you’ll tell to
Zend_Paginatorwhich Adapter it must use to access your data.This Adapter will be specific to “Data that is fetched via an SQL query“, and will know how to paginate it directly on the database side — which means fetching only what is required, and not all data like you initialy did.