Hoping some of you PHP/MySQL guys can help me.
I have a database with a bunch of tables. I have a script that gets some data from a provider and populates the related tables. I repopulate the tables once a day. Everything works fine.
I need to extend some functionality to track when records are new. This requires me to get the data daily, but only insert the NEW data (or update changed data), while retaining the existing (unchanged) data. I assign a time stamp to the records when they are initially inserted.
I'm trying to determine the best approach to retrieving the records from the provider and checking my database.
My issue is that I'm a little green on doing a crap load of stuff during MySQL queries. Currently, my thinking is that I need to cycle through the array of results from the provider, and:
- query my db for a record according to a common, unique field (not a problem, since this is in place).
-- if it matches, see if the fields I need to monitor match
--- if they do, do nothing and move to the next record
--- if they don't, update the record and timestamp
-- if it doesn't match, insert the new record and timestamp.
This means I'm making two mysql_query() calls for each record. Multiply that by the number of records I have (~900 now, but up to 30k later), and we have a LOT of queries going on.
I can deal with this if I need to, since it's only happening once a day. But, I thought I would ask and see if you guys can provide an example of a better method.
Note: Before the need to track everything, I would merely empty the tables each day and repopulate them. But, alas, my needs dictate that I can't do that any more.