I am uploading csv file contents into mysql database. I am not sure which approach is best & efficient & nice.
1] Using the LOAD DATA INFILE SQL statement
LOAD DATA LOCAL INFILE '/importfile.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3);
2] Using a script to parse and import the file for e.g. fgetcsv() function in php
LOAD DATA LOCAL INFILEfor speed and ease of use.fgetcsv(), you will either need to call multipleINSERTstatements, or write a bunch of code to build one very longINSERTstatement with aVALUES (),(),(),(),()...chain. A native CSV import in MySQL will be far easier.