How does MySQL use PHP to batch insert? For example, the first 1000 data processing after the end of processing 1001 to 2000, and then processing 2001 to 3,000 ... Until the whole process is complete.

Source: Internet
Author: User
How does MySQL use PHP to batch insert? For example, after the end of the first 1000 data processing, then processing 1001 to 2000, and then processing 2001 to 3,000 ... until the whole process is finished?
When the amount of data in the table member is small, it can be executed once:

$q = "SELECT * from member '";
$r = $obj _db->simplequery ($q);
while ($a = $obj _db->fetchrow ($r, Db_fetchmode_assoc)) {
$id = $a [id];
$MCCD = $a [cca]+ $a [CCB];

$query = "INSERT into Mingxi (mid,mccd,mtime) VALUES (' $id ', ' $MCCD ', ' $time ')";
$obj _db->simplequery ($query);
}


However, when the amount of data in the member reaches millions, the execution timeout error is said to occur:
Fatal error:maximum execution time of seconds exceeded in D:

So how to real-batch processing, such as the first 1000 data processing after the end of processing 1001 to 2000, and then processing 2001 to 3,000 ..., until the whole process is complete?

$q = "SELECT * from member '";
$r = $obj _db->simplequery ($q);
while ($a = $obj _db->fetchrow ($r, Db_fetchmode_assoc)) {
$i + +;

$ep =1000;//This assumes that the 1th 1000 is processed and then the second 1000 is processed until the end of processing?

$id = $a [id];
$MCCD = $a [cca]+ $a [CCB];

$query = "INSERT into Mingxi (mid,mccd,mtime) VALUES (' $id ', ' $MCCD ', ' $time ')";
$obj _db->simplequery ($query);
}



Please help write detailed code, thank you! Because the code is hidden in the background, so don't consider the page by page by hand to point the way
------Solution--------------------
You can use the INSERT into Mingxi (mid,mccd,mtime) Select ID, CCA+CCB, and time from member
------Solution--------------------
$offs = isset ($_get[' offs ')? $_get[' offs ': 1;
$sql = "SELECT * from member limit $offs, 1000";
Do what you need to do.
Header ("Location: $_server[php_self]?offs=". ($offs +1000));

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.