Hemant Maurya
Hemant Maurya

Reputation: 55

While Uploading and importing very large data file(CSV) Adding " in all the column

I am trying to upload csv files to a table with following query

mysqli_query($cons, '
LOAD DATA LOCAL INFILE "crypto/blog/csv/' . $file . '"
    INTO TABLE ' . $table . '
    FIELDS TERMINATED by \',\'
    LINES TERMINATED BY \'\n\'
 ');

It is saving all the data, No problem but it is adding quates (") in starting and end of all the columns Ex

"London"

whats wrong with my query.

Upvotes: 0

Views: 32

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239814

If the CSV data is quoting the fields, you need to use the ENCLOSED BY option:

mysqli_query($cons, '
LOAD DATA LOCAL INFILE "crypto/blog/csv/' . $file . '"
    INTO TABLE ' . $table . '
    FIELDS TERMINATED by \',\' ENCLOSED BY \'"\'
    LINES TERMINATED BY \'\n\'
 ');

Upvotes: 1

Related Questions