MYSQL +加载数据INFILE +检查字段

时间:2012-05-19 11:36:52

标签: mysql file csv

我对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文件:

enter image description here

1 个答案:

答案 0 :(得分:3)

要跳过一行,请将加载字符串更改为:

$query  = "LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE $db FIELDS TERMINATED BY ';' IGNORE 1 LINES ($dbq)";