I have a php script which runs continuously several hours and every few seconds I have new data to save in a database. So I have the option to store new data when it becomes available or gather them in an array and save them once I have 100 or 500. If I’m correct php cannot send multiple insert queries to the database so the two options above would take the exact same amount of time to save.
Am I wrong or one is faster than the other? Perhaps there is a third solution faster than these?
You could use the following syntax to insert multiple rows at a time:
or, you could dump the data to a delimited file as you get it and when you get to 100 or so lines in the file use LOAD DATA INFILE (http://dev.mysql.com/doc/refman/5.5/en/load-data.html) to do the insert. I’ve found that LOAD DATA INFILE is very efficient for importing large amounts of data.