Reputation: 55
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
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