Database batch write judgment problems I do a function is an order import function, the data in the xls is imported into mysql, each time about 1000.
The problem is that each record has an encoding. First, check whether the encoding system has been set up and imported, if the entire batch is not imported into the system, what should I do ??
Reply to discussion (solution)
I don't understand. each record has a single encoding, but this encoding is not properly configured. Why can't I import the entire batch? Isn't this one?
If the one I want cannot be imported, do the following:
Read the 1000 pieces of data from the XLS file, read the encoding table from the database, create an array using the encoding as the primary key, and then read your 1000 pieces of data cyclically, each time you use the encoding of this data to find whether the encoding array exists. if it does not exist, it is skipped. if it exists, it is saved to the database. Of course, you can write SQL statements and save them at the last time.
Can I elaborate on jzh2004?
Let me talk about it. we will download an order details from the Internet, that is, the order details for sale every day. each record contains a material code, on this page, I import order details to a PHP ERP system, but sometimes new material colleagues forget to add them to the ERP system. I just want to make a judgment. first, I should judge whether all the 1000 records in the order details are available in the ERP system. if there is none, the import will be stopped.
It's nothing to look!
It is easy to implement.
First check whether the encoding exists (select)
Insert based on the result)
Obviously, your system uses a foreign key (it is purely for yourself)
In fact, direct insertion does not matter. it is not an error or the insertion is invalid.