php - Updating Database From Static File JSON Feed -


i have php script pulling json file static , updates every 10 seconds. has details events happen , adds top of json file. insert them mysql database.

because have pull every event every time pull file, inserting new events. easy way search event in database (primary keys not same), talking ~4000 events every day, , not want many queries see if exists.

i aware of insert ignore, looks uses primary_key this.

what can (preferably easily) prevent duplicates on 2 keys?

example:

i have table events following columns:

  • id (irrelevant, really)
  • event_id (that need store source)
  • action_id (many action_ids belong 1 event_id)
  • timestamp
  • whatever...

and data json comes out on first pull this:

event_id|action_id|...    1    |   1    1    |   2    1    |   3    2    |   1    2    |   2    2    |   3 

then next pull this:

event_id|action_id|...    1    |   1    1    |   2    1    |   3    1**  |   4**    1**  |   5**    2    |   1    2    |   2    2    |   3    2**  |   4** 

i only want rows marked asterisks inserted, , others ignored. remember, primary_key column id in table, , use ubiquity.

what command can use "insert" every event pull, adding aren't duplicated way of 2 columns event_id , action_id.

thanks.

create unique index of both columns.

create      unique index event_action     on tablename (event_id, action_id)   

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -