Import question

I have a php script that generates a Mysql string that imports information from a csv file into a Mysql database. I can import new records from the database but not update existing records. I am thinking this is a Mysql string problem and not a php issue.

This one works fine… It imports new records into the database.

LOAD DATA LOCAL INFILE ‘C:/wamp/www/test/files/upd101010.csv’ INTO TABLE email FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ’ \r
’ IGNORE 1 LINES (fname, lname, city, state, zip, eaddress, reason, message);

This one will not update the existing records…

LOAD DATA LOCAL INFILE ‘C:/wamp/www/test/files/upd101010.csv’ INTO TABLE email FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ’ \r
’ IGNORE 1 LINES (id, fname, lname, city, state, zip, eaddress, reason, message);

The only difference between the two is that the update string has the id field and the new record string does not. How can I modify the existing record string to cause it to update the records?

Good idea… Thank You very much…

load your data into an “incoming” table

then use INSERT INTO with the ON DUPLICATE KEY UPDATE option to insert the rows from the incoming table to your target email table

this strategy separates the loading from the processing, which is usually a good idea