Just a point: from MySQL Manual at
http://dev.mysql.com/doc/mysql/en/Insert_speed.html
When loading a table from a text file, use LOAD DATA INFILE. This is usually 20 times faster than using a lot of INSERT statements. See section 14.1.5 LOAD DATA INFILE Syntax.
http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html
So, I prefer to use LOAD DATA INFILE rather than looping through an array INSERT ing 1 row at a time. It is also simpler to code one SQL statement for execution rather than building an array and then the loop.
Just an idea.