0

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

1 Answer 1

1

No. LOAD DATA INFILE does exactly what it says. You will have to remove the duplicates separately.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I'll clean the data before importing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.