r0skar
r0skar

Reputation: 8696

MYSQL+Load data INFILE + Check fields

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:

enter image description here

Upvotes: 2

Views: 1075

Answers (1)

Phil
Phil

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

Related Questions