English 中文(简体)
Zend_Paginator;它是否优化?
原标题:Zend_Paginator; is it optimized?

我即将在我的项目中使用Zentd_Paginator。 我在互联网上发现了该阶级的例子。 其中之一是:

$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;

在第一行,它实际上从表_名称中选择了所有各行。 如果我有一张有500万字的桌子? 这将非常低效。

是否有其他办法使用Zentd Paginator?

最佳回答

关于这个问题,你可能有兴趣了解手册的这一部分:39.2.2. The DbSelect and DbTableSelecter Adaptation, which states(引引引引引引引引引引引引引引引引引引引引引引,强调):

... the database adapters require a more detailed explanation.
Contrary to popular believe, these adapters do not fetch all records from the database in order to count them.

Instead, the adapters manipulates the original query to produce the corresponding COUNT query.
Paginator then executes that COUNT query to get the number of rows.

This does require an extra round-trip to the database, but this is many times faster than fetching an entire result set and using count().
Especially with large collections of data.

www.un.org/Depts/DGACM/index_arabic.htm


The idea is that you will not fetch all data yourself anymore, but you ll tell to Zend_Paginator which Adapter it must use to access your data.

该校将专门设计成“Data,通过Qry <>/em>进行,并知道如何直接在数据库中加以gin,这意味着只需要什么,而不是像你最初那样的所有数据。

问题回答

我建议通过<条码>Zend_Db_Select 反对,作为<条码>Zend_Paginator: 因素(当选);,而不是通过结果浏览。 否则,你就重新选择了全部结果,然后进行想象。 在你目前的解决办法中,如果你有100万个牢房,你在获得本页所定义的囚室之前就选择所有这些牢房。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...