Alternatively: use fgetcsv() and programmatically create the inserts.
change
To avoid using resources using fgetcsv() [because it tries to read the entire file right away], you can create a loop like the one below to read / paste managed snippets.
<?php $fname = 'myfile.csv'; $chunksize = 50; if( ! $fh = fopen($myfile, 'r') ) { throw new Exception("Could not open $fname for reading."); } $i=0; $buffer = array() while(!feof($fh)) { $buffer[] = fgets($fh); $i++; if( ($i % $chunksize) == 0 ) { commit_buffer($buffer); //run inserts $buffer = array(); //blank out the buffer. } } //clean out remaining buffer entries. if( count($buffer) ) { commit_buffer($buffer); } function commit_buffer($buffer) { foreach( $buffer as $line ) { $fields = explode(',', $line); //create inserts } //run inserts $buffer = array(); //blank out the buffer. }
Thus, at any given time, only $chunksize strings are stored in memory.
You will most likely need additional code to handle things like encapsulated strings containing commas and line breaks, but if you cannot get LOAD DATA LOCAL INFILE , I see no other choice.
source share