I'm trying to import a csv file to my mysql database, but I can't get it to work. I looked up a lot of solutions on this website, but none of them seems to solve it.
I'm getting the error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LOAD DATA INFILE 'name.csv' INTO TABLE test FIELDS TERMINATED BY ',' ' at line 2.
This is my name.csv file and my php code:
productId,ean,title
10060,8720094110226,KATRIZ Epson
10059,8720082041877,Lexmark 14L0198
$link = mysqli_connect("localhost", "username", "password", "");
$query = <<<eof
USE `db_name`;
LOAD DATA INFILE 'name.csv'
INTO TABLE `tablename`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(productId,ean,title)
eof;
if ($result = mysqli_query($link, $query)) {
echo "successful";
} else {
printf("Errormessage: %s\n", mysqli_error($link));
};
I expect SQL to upload the name.csv file into my table tablename
, but it's not working. My connection to the database gives no errors.