Question

I'm trying to insert .csv file in my database. I've got about 300k rows in my file but only 5k are actually inserted in my table.

I do

 //Create a table like the one actually holding the same data
 $tmp_table_query = "CREATE TABLE test LIKE Model;";
\DB::connection()->getpdo()->exec($tmp_table_query);

//Insert data in it
$query = sprintf("LOAD DATA local INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 0 LINES", addslashes($file));
\DB::connection()->getpdo()->exec($query);

Here's a sample of my data. The two first row are inserted but not the two last

//Some data...
161041,12/8/2013 13:28:23,"A5",1,150,8009892,9792108,-1,9792108,5000,0,0,0,500,9797108,0,9797534,3,3,424,1,0,0,9797535,1425,-1,-1,0,0,0,0,0
161042,12/8/2013 13:28:23,"A5",1,151,8009892,9798962,9808807,9798962,5000,0,0,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,9803807,5000,1,0,0,0,0
161043,12/8/2013 14:00:48,"A25",1,1,9881742,9882184,-1,9882184,5000,0,0,0,500,9887184,0,9887995,1,1,809,1,0,0,9887996,1329,-1,-1,0,1,0,0,0
161044,12/8/2013 14:00:48,"A25",1,2,9881742,9889327,-1,9889327,5000,0,0,0,500,9894327,0,9895199,0,0,870,1,0,0,9895200,1616,-1,-1,0,0,1,1,0
//Some more data...
Was it helpful?

Solution

Actually, it was a problem with the table I used which didn't had a primary key properly set.

I set my id column as primary, I changed the collation of the row containing the "A25" and that solved my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top