显示很多mysql记录 [英] Display lots of mysql records

查看:70
本文介绍了显示很多mysql记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个带有7000条记录的mysql数据库,而我必须在我的网页上显示所有7000条记录.是否有任何提示和技巧可以加快该过程(浏览器在显示所有记录之前实际上已崩溃),我知道我应该对其进行查询以减少所选记录的数量,但实际上我需要显示7000 ...

If i had a mysql db with 7000 records in it and i had to display all 7000 on my webpage. Are there any tips and tricks to speed the process up (the browser practically crashes before showing all the records) i know i should query it to reduce the number of records selected but i actually need to display 7000...

推荐答案

打开输出缓冲: 编辑

以下php提取10K产品并将它们输出为表格,在0.014秒内没有问题.

The following php fetches 10K products and outputs them as a table with no problems in 0.014 seconds.

<?php

ob_start(); 

$conn = new Mysqli("localhost", "vldb_dbo", "pass", "vldb_db");

$startTime = microtime(true);

$result = $conn->query(sprintf("call list_products(%d)", 10000));

echo "<table border='1'>";

while($row = $result->fetch_assoc()){
 echo sprintf("<tr><td>%s</td><td>%s</td></tr>", $row["prod_id"], $row["name"]);
}

echo "</table>";

echo sprintf("<br/>Page generated in %s secs",number_format(microtime(true) - $startTime, 6, ".", ""));

$result->close();   
$conn->close();

ob_end_flush();

?>

SQL脚本

drop procedure if exists list_products;
delimiter #

create procedure list_products
(
in p_prod_id int unsigned
)
begin
    select * from product where prod_id between 1 and p_prod_id;
end #

delimiter ;

除了运行时潜水外,还可以处理5万条记录-页面生成时间为0.112902秒

Works fine with 50K records too except runtime dives - Page generated in 0.112902 secs

EDIT2

http://phplens.com/lens/php-book/Optimization-debugging-php.php

上述链接的摘录:

加快上述速度的另一种方法 代码将使用输出缓冲. 这将累积输出字符串 内部,然后将输出合二为一 在脚本结尾处拍摄.这 减少网络开销 实质上以更多为代价 内存和延迟的增加.在 我的一些代码完全由 回声语句,性能 改善了15% 观察到.

An alternate way of speeding the above code would be to use output buffering. This will accumulate the output string internally, and send the output in one shot at the end of the script. This reduces networking overhead substantially at the cost of more memory and an increase in latency. In some of my code consisting entirely of echo statements, performance improvements of 15% have been observed.

这篇关于显示很多mysql记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆