Currently I'm using the following to import a CSV file in to a table.
$query = <<<eof
LOAD DATA LOCAL INFILE 'list.csv'
INTO TABLE pupils
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
( -- Field List -- )
eof;
if ($conn->query($query) === TRUE) {
echo "Data Imported successfully";
} else {
echo "Error importing data: " . $conn->error;
}
-- Field List -- is a comma separated list of fields.
This works well and imports the data from the CSV file in to the table.
I've got a new CSV to import and there are going to be some entries that already exist in the database. During the import is it possible to check if a entry already exists ?
My Database has a field called remote ip which will be unique for each entry. Is there anyway to check if it exists and it it does don't import that row from the CSV ?
Thanks