I’ve got a PHP script pulling a file from a server and plugging the values in it into a Database every 4 hours.
This file can and most likely change within the 4 hours (or whatever timeframe I finally choose). It’s a list of properties and their owners.
Would it be better to check the file and compare it to each DB entry and update any if they need it, or create a temp table and then compare the two using an SQL query?
None.
What I’d personally do is run the
INSERTcommand usingON DUPLICATE KEY UPDATE(assuming your table is properly designed and that you are using at least one piece of information from your file asUNIQUEkey which you should based on your comment).Reasons
Creating temp table is a hassle.
Comparing is a hassle too. You need to select a record, compare a record, if not equal update the record and so on – it’s just a giant waste of time to compare a piece of info and there’s a better way to do it.
It would be so much easier if you just insert everything you find and if a clash occurs – that means the record exists and most likely needs updating.
That way you took care of everything with 1 query and your data integrity is preserved also so you can just keep filling your table or updating with new records.