How to optimize php Import data

upload excel, parsing data. If there are a thousand pieces of data
, the system will cycle to query whether each data already has the same record in the database, there is no addition, and there is no processing
how to optimize

.
Mar.06,2021

Don't check the database one by one

if the amount of the database is small, you can check it out first, compare it with these 1000 pieces of data, and record them unequally. These are the data you want to add

.

if the database is very large, you can check these 1000 pieces of data once. For example, if they are associated with ID, you can use in or not in to check the corresponding ID

.

convert single queries and single-challenge additions into batch queries and batch additions. The first floor makes it very clear


try using replace into. If the same data exists, the previous replacement will be updated, if it does not exist, insert


you can use the intersection and difference of arrays!
database exists-the file you upload also exists = intersection
database does not exist-the difference
difference in the file you upload needs to be written, and the intersection does not matter

.
Menu