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

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e6314b-444da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e6314b-444da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?