Load Data Infile
Jeg vil gerne loade en csv fil til en database tabel via PHP. Når jeg bruger PhpMyAdmin's form til det, bruger den følgende sql statementLOAD DATA INFILE 'C:\\WINDOWS\\TEMP\\php116.tmp' INTO TABLE `branche_fri`
FIELDS TERMINATED BY ';'
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
Jeg har prøvet at skrive det ind i PHP som følger:
$res= db_query("LOAD DATA INFILE '$branch_filename' INTO TABLE `branch_db_table`
FIELDS TERMINATED BY ';'
ENCLOSED BY '\"'
ESCAPED BY '\\'
LINES TERMINATED BY '\\r\\n' ");
Men får følgende fejl:
Error in function mysql_query:
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 '\r\n'' at line 4
Query:
LOAD DATA INFILE 'Tekniq.csv' INTO TABLE `branch_db_table`
FIELDS TERMINATED BY ';'
ENCLOSED BY '"'
ESCAPED BY '\'
LINES TERMINATED BY '\r\n'
Jeg indrømmer gerne at jeg ikke helt har styr på escaping.
Nogle der kan hjælpe?
Venlig hilsen kristian