I have an application where I would like a user to be able to upload an spreadsheet which will end up being inserted into one of our PostgreSQL database tables. The guys that will be doing the uploading will not want to / not know how to save as CSV or other delimited files. so opting for the phpExcel class which I can use to generate:
- an array of each row in the sheet
- a multi dimensional array of the entire sheet
I could iterate each row and perform an insert for each one, but this could be a little heavy on the database so I was trying to find out if anyone knows of a way to populate a table quickly and efficiently from a multidimensional array:
e.g.
<?php
$data['row1'] = array('column1','column2','column3','column4');
$data['row2'] = array('column1','column2','column3','column4');
$data['row3'] = array('column1','column2','column3','column4');
// Some PSQL Insert.
?>
Thanks in advance.
insert into t (...) values (...), (...), (...)
. So chunk it into pieces of a size that works and wrap the whole thing in a transaction (or several transactions depending on what happens in real life). – mu is too short Nov 16 '13 at 23:55