fail
12-08-2009, 07:11 AM
I have a problem with a file import to MySQL. Not sure if this belongs to MySQL or PHP. Via phpmyadmin it works fine with this string:
LOAD DATA INFILE 'C:\\xampp\\tmp\\import.csv'
INTO TABLE `parts`
FIELDS TERMINATED BY ','
ENCLOSED BY '"' ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
Works perfectly. phpmyadmin generates me this php code:
include("connect.php");
$sql = "LOAD DATA LOCAL INFILE \'C:\\\\xampp\\\\tmp\\\\parts_import.csv\'
INTO TABLE `parts`
FIELDS TERMINATED BY \',\'
ENCLOSED BY \'\"\'
ESCAPED BY \'\\\\\'
LINES TERMINATED BY \'\\r\\n\'# 481 row(s) affected.\n"
. "";
$result = mysql_query($sql);
echo mysql_error();
echo $result;
That results in into this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'C:\\xampp\\tmp\\import.csv\' INTO TABLE `parts` FIELDS TERMINATE' at line 1
I presume the error is with one, or several of the '/', but after trying about 1000 different strings I give up now. I hope anybody has a hot hint for me.
LOAD DATA INFILE 'C:\\xampp\\tmp\\import.csv'
INTO TABLE `parts`
FIELDS TERMINATED BY ','
ENCLOSED BY '"' ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
Works perfectly. phpmyadmin generates me this php code:
include("connect.php");
$sql = "LOAD DATA LOCAL INFILE \'C:\\\\xampp\\\\tmp\\\\parts_import.csv\'
INTO TABLE `parts`
FIELDS TERMINATED BY \',\'
ENCLOSED BY \'\"\'
ESCAPED BY \'\\\\\'
LINES TERMINATED BY \'\\r\\n\'# 481 row(s) affected.\n"
. "";
$result = mysql_query($sql);
echo mysql_error();
echo $result;
That results in into this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'C:\\xampp\\tmp\\import.csv\' INTO TABLE `parts` FIELDS TERMINATE' at line 1
I presume the error is with one, or several of the '/', but after trying about 1000 different strings I give up now. I hope anybody has a hot hint for me.