So I need some help, I'm stuck on this for hours. So I have this array of data in PHP which I write into a CSV file using the fputcsv function. Now the data gets saved into a CSV file and it is of the following format:
Becoming Human, "becoming_human_uk", "2011",
Bed of Roses, "bed_of_roses", "2008",
Bed of Roses, "Bed_of_Roses_2008", "2008",
Bedlam, "bedlam", "2011",
This goes on for ~10k more rows. Now up to this point it is all hunky dory. However now I want to import all of this data from the CSV to my database table. To do this I use the LOAD DATA INFILE mysql function of the following format:
$sql="LOAD DATA INFILE 'path/series.csv' INTO TABLE series FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' (title, link, year)";
It is now here where the problem lies. Only one row gets inserted into the database and its the first row. I suspect the problem lies in these optional parameters like TERMINATED BY or ENCLOSED BY. I put fields to optionally enclosed by because the first field is not enclosed in "" while the other two are. Also the fields terminate by (,) so I guess that is ok. This only leaves the line termination and I don't know if this is correct. There might be something else wrong with this. Or can I somehow better format the input of the data into the CSV so that all the fields are enclosed the same way. So if someone can help me spot the problem here I would greatly appreciate it. Thanks.