PHP MYSQL UPDATE if Exist or INSERT if not?

I believe you are looking for the following syntax: INSERT INTO <table> (field1, field2, field3, …) VALUES (‘value1’, ‘value2′,’value3′, …) ON DUPLICATE KEY UPDATE field1=’value1′, field2=’value2′, field3=’value3’, … Note: With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row … Read more

MySQL LOAD DATA INFILE with ON DUPLICATE KEY UPDATE

These steps can be used to emulate this functionality: Create a new temporary table. CREATE TEMPORARY TABLE temporary_table LIKE target_table; Optionally, drop all indices from the temporary table to speed things up. SHOW INDEX FROM temporary_table; DROP INDEX `PRIMARY` ON temporary_table; DROP INDEX `some_other_index` ON temporary_table; Load the CSV into the temporary table LOAD DATA … Read more