Batch insertion of data to MySQL database using php

前端 未结 3 1222
抹茶落季
抹茶落季 2021-01-14 03:10

I have a thousands of data parsed from huge XML to be inserted into database table using PHP and MySQL. My Problem is it takes too long to insert all the data into table. Is

3条回答
  •  感情败类
    2021-01-14 03:55

    You should put it as said before in a temp directory with a cron job to process files, in order to avoid timeouts (or user loosing network).

    Use only the web for uploads.

    If you really want to import to DB on a web request you can either do a bulk insert or use at least a transaction which should be faster.

    Then for limiting inserts by batches of 100 (commiting your trasnsaction if a counter is count%100==0) and repeat until all your rows were inserted.

提交回复
热议问题