Reputation: 8696
I have two questions regarding the MYSQL LOAD DATA FILE
function:
1) How can I make sure all fields in the data file
are set?
2) Can I make it skip the first row of the data file
?
The code I am currently working with:
$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");
}
And the data file
is a .csv
file:
Upvotes: 2
Views: 1075
Reputation: 2422
To skip a line, change your load string to:
$query = "LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE $db FIELDS TERMINATED BY ';' IGNORE 1 LINES ($dbq)";
Upvotes: 3