Sunday 15 June 2014

php - Zend_Paginator; is it optimized? -


I'm going to use the Zend_Paginator class in my project. I found examples of class on the Internet, one of them is

  $ sql = 'Select' from 'table_name'; $ Result = $ db- & gt; Get all ($ sql); $ Page = $ this- & gt; _getParam ('pages', 1); $ Paginator = Zend_Paginator :: Factory ($ results); $ Paginator-> SetItemCountPerPage (10)); $ Paginator-> SetCurrentPageNumber ($ page); $ This- & gt; View-> Paginator = $ paginator;  

On the first line, it will actually pick all the rows from table_name what if I have 50000 lines? It would be very disabled.

Is there any other way to use Zend Pageant?

Regarding this problem, you may be interested in this section of the manual: ( Quotation, Zor Khan) :

... database adapters require more detailed explanation
Contrary to popular belief, to calculate these adapters database Do not get all records from Instead, the adapter adds the original query to create the corresponding COUNT query
legs Greater then execute COUNT query to get the number of rows.

This requires additional rounds of databases to travel, but bring the whole result set and multiply it by using count () It's fast.
Especially with large collection of data

(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 bring all the data yourself , but you should use the Zend_Paginator adapter to access your data.

This adapter will be specific to " data that is brought through SQL query ", and how it will be found directly on the database side - which means that only the required Which is being brought, and not initially all the data like you.


No comments:

Post a Comment