简体   繁体   中英

mysql_query Select limited at 525 results

I have a select and is limited at 525 results otherwise the while will stuck.

    $query_other = "SELECT * FROM prod where active=1 and aprobat=1";
    $other = mysql_query($query_other, $conn) or die(mysql_error());
    while($row = mysql_fetch_assoc($other)){
        $other_prod[]=$row;
    } 

In cpanel it shows more than 525 and when i did var_dump on $other its says resource(525) of type (mysql result). Its on Apache Server if that helps.

If i put LIMIT 525 it works and show all page otherwise is just blank page. Anything after the while doesn't work.

PS : I know mysql_ is deprecated i hate it but is required at the task and i have no power over it.

如果问题确实是内存,则可以使用以下方法动态增加内存:

ini_set("memory_limit","512M"); //i.e. change the memory_limit to 512M, you should specify more than current limit.

Increasing memory won't help. It's just a temporary fix. Plus you need to think of multiple clients doing the same query at the same time. How's the system going to keep up with the memory consumption.

BUT be selective about the fields you need to pull back.

Don't :

SELECT *

Do :

SELECT `field1`, `field2`, ...

This will decrease memory consumption and let you deal with things. I imagine you don't need all the rows. And you especially want to avoid TEXT / BLOB ones as they are usually large. Select them only when you need to display/use them.

You can also use :

LIMIT 0, 100

to paginate through the results. Might help you a bit but I'd select the right fields to fix this permanently.

Also set :

ini_set('display_errors', true);
error_reporting(-1);

and see if PHP tells you more about what goes wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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