mysql - PHP Upload CSV to update database records but exclude duplicate -


i'm trying figure out best way this. have database around 500 records/rows in mysql , need update daily. problem file upload excel file (i need convert csv before upload?). need upload records don't exist yet in current mysql database. unique field named "memberid".

what best way achieve this? if insert each rows (so can check first if record/row should inserted database) 1 one using loop, slow process uploading 500 records?

i'm new php vba programming , know how insert records 1 @ time. suggestions appreciated.

you've got 3 options:

  1. replace (recommended you're using database that's updated daily - you'll never know, if old records didn't change last update):

    replace db_name (id,value) values (1,1),(1,2),(1,3),(1,4) 

    it affect rows.

  2. on duplicate key update (that's you've been searching for, update whatever want or leave row 'as is'):

    insert db_name (id,value) values (1,1) on duplicate key update id=id 
  3. insert ignore into (it update rows that're new, skipping duplicates, if you'll encounter key violations mysql not raise error):

    insert ignore db_name (id,value) values (1,1); 

also, alternatives: sql merge.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -