Importing Data, checking for existense in database
Posted: Fri Aug 06, 2010 5:32 am
Hi,
I am developing some software (being fairly new to PHP/mySQL this is proving to be a big learning curve
).
I need to import data from an external source, via their api, insert it into the database, then aprox every hour, import the data again, check it against the database, and do the following actions:
The PHP/JSON output will be like this:
My question:
How do I query the database, to see if entry exists, then either 1) add entry 2) delete entry or 3) Do nothing if entry already exists?
Sorry but this has really got me stumped. I apreciate any help you can give
__________
Regards
Gareth
I am developing some software (being fairly new to PHP/mySQL this is proving to be a big learning curve
I need to import data from an external source, via their api, insert it into the database, then aprox every hour, import the data again, check it against the database, and do the following actions:
- If entry exists in database, do nothing
If entry does not exist in database, add it to database
If entry exists in database, but not on the new external source array, then delete record in database
The PHP/JSON output will be like this:
Code: Select all
array(
array(
'phish_id' => 123456,
'url' => 'http://www.example.com/',
'phish_detail_url' => 'http://www.phishtank.com/phish_detail.php?phish_id=123456',
'submission_time' => '2009-06-19T15:15:47+00:00',
'verified' => 'yes',
'verification_time' => '2009-06-19T15:37:31+00:00',
'online' => 'yes',
'target' => '1st National Example Bank',
'details' => array(
array(
'ip_address' => '1.2.3.4',
'cidr_block' => '1.2.3.0/24',
'announcing_network' => '1234',
'rir' => 'arin',
'detail_time' => '2006-10-01T02:30:54+00:00'
)
)
)
)
How do I query the database, to see if entry exists, then either 1) add entry 2) delete entry or 3) Do nothing if entry already exists?
Sorry but this has really got me stumped. I apreciate any help you can give
__________
Regards
Gareth