简体   繁体   中英

Insert a lot of records into database

I have a list with a lot of (500+) codes and I want to insert it into database.

For example: User given codes to textarea and codes are seperated by new line ( \\n ). In PHP it is $_POST['codes'] . Of course I can just use explode() function and insert all codes in loop, but I'm thinking it's not a good idea with 500 repeatitions.

So, how can I do this the most optimal?

Depending on the size of your data, you could make it all into a single query if you are worried about number of separate inserts:

mysql_query("INSERT INTO mytable(`People`, `Places`, `Ideas`, `things`)
             VALUES ('40', '15', '0',  '0'),
             ('0',  '5',  '10', '0'),
             ('10', '0',  '11', '12')");

(example from: https://stackoverflow.com/a/10286687/486780 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM