简体   繁体   English

mysql限制结果?

[英]Mysql limit of results?

I have a table with approximatly 1000 records. 我有一张约有1000条记录的表。

I have a request : 我有个请求 :

$select = "SELECT * FROM ophlm_ancien.patrimoine";
$result = mysql_query($select);
while($p = mysql_fetch_array($result)){
    //some actions
}

If a run my script, i have this error on firefox : The connection was reset 如果运行我的脚本,则在firefox上出现此错误: The connection was reset

I a add a LIMIT 500, it work. 我添加一个LIMIT 500,它可以正常工作。 LIMIT 600 too. 上限也为600。 But after i always have this error. 但是之后我总是有这个错误。

Do you have any ideas ? 你有什么想法 ?

增加服务器上的max_allowed_packet

Up to the documentation you can combine the LIMIT with an offset: 根据文档,您可以将LIMIT与偏移量结合使用:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

Which lets you kind of buffer the results: 这使您可以缓冲结果:

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT子句可用于约束SELECT语句返回的行数。 LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements). LIMIT接受一个或两个数字参数,这两个参数都必须是非负整数常量(使用预处理语句时除外)。

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. 有两个参数,第一个参数指定要返回的第一行的偏移量,第二个参数指定要返回的最大行数。

All you need to do is to execute the selects in a loop and match the offset in each round until you get all results. 您要做的就是循环执行选择,并在每一轮中匹配偏移量,直到获得所有结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM