我对MYSQL LOAD DATA FILE
函数有两个问题:
1)如何确保data file
中的所有字段都已设置?
2)我可以跳过 data file
的第一行吗?
我目前正在处理的代码:
$dbq = "field1,field2,field3,field4";
$query = "LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE $db FIELDS TERMINATED BY ';' ($dbq)";
$result = $mysqli->query($query);
if(!$result){
echo($mysqli->error+".");
exit();
} else{
header("Location: admin.php");
}
data file
是.csv
文件:
答案 0 :(得分:3)
要跳过一行,请将加载字符串更改为:
$query = "LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE $db FIELDS TERMINATED BY ';' IGNORE 1 LINES ($dbq)";