0

I Have an array with all the id's in my MySQL DB. In second array, have ID's which I need to insert into the same table. I need to check if the Id's which I am going to insert are present in first array or not and then insert it into the DB.

Help me out in finding the unique values.

Trogvar
  • 856
  • 6
  • 17

2 Answers2

0

If the ids are PKs, you can use insert on duplicate update (here is a stack question that might help you; unrelated, but for syntax) On duplicate key ignore?.

Community
  • 1
  • 1
zozo
  • 8,230
  • 19
  • 79
  • 134
0

Use array_intersect() function to find out whether two arrays satisfy your conditions and then make a decision whether data can be inserted to DB

Trogvar
  • 856
  • 6
  • 17