LOAD DATA INFILE not working with FIELDS TERMINATED BY
I'm using th开发者_运维问答e sql below in a php script:
$sql1 = "LOAD DATA LOCAL INFILE 'test1.csv' INTO TABLE number1 (order_num,pname)";
$sql2 = "LOAD DATA LOCAL INFILE 'test1.csv' INTO TABLE number1 (order_num,pname) FIELDS TERMINATED BY ':'";
if ($result = $mysqli->query($sql)) {
printf("<br>Section 4: %s",$mysqli->error);
printf("|$result|$table");
} else {
printf("<br>Section 5: %s",$mysqli->error);
}
If I use $sql1
it properly brings 3 lines into the db (doesn't break them into proper fields). No error returned. If I use $sql2
it returns message:
"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 'FIELDS TERMINATED BY ':'.."
I've tried different order, using ENCLOSED BY with it / instead of it.. Everything I can think of. Anyone have a suggestion?
Check the documentation... The field declaration must come after the fields terminated by declaration:
$sql2 = "LOAD DATA LOCAL
INFILE 'test1.csv'
INTO TABLE number1
FIELDS TERMINATED BY ':'
(order_num,pname)";
Yep the (order_num,pname) is invalid there's a different syntax for mapping fields to column names.
精彩评论