简体   繁体   中英

SQL with many results in PHP

I have an SQL that brings back all the users of a system in a MySQL database with PHP and I need to get these users and move them to another system (don't worry about the fields, I already map them). The problem is that I have more than 67000 users in the database. Is there any way I can do that with PHP and get all the results at once?? Cause I tried and give me a error, not an error, but the PHP can't return all the results at once.

You probably have reached PHP's default memory limit. You have (at least) 2 options:

  1. fetch them all at once (like you do now), and increase the memory PHP may use in that script. You can find it under the name "memory_limit". http://nl3.php.net/manual/en/ini.core.php Take care you only do that for your current script, not systemwide by modifying php.ini.
  2. Fetch your records in smaller batches, like 1000 per time. That way you won't hit your memory limit.

In both cases you might want to increase the time your script can run too. Have a look at max-execution-time.

http://nl3.php.net/manual/en/info.configuration.php#ini.max-execution-time

Put this on top of your PHP script: ini_set('memory_limit', '512M');

You can give the php script less that 512MB ofc

You can use limit in SQL

limit 0, 1000

limit 10001, 2000

etc

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