I have a script that captures tweets and puts them in a database. I will run the script on cronjob, and then display the tweets on my site from the database, in order to prevent restrictions on the twitter API.
So, I do not want to have duplicate tweets in my database, I understand that for this I can use "INSERT ... ON DUPLICATE KEY UPDATE", but I do not quite understand how to use it.
My database structure is as follows.
Table - Hash id (auto_increment) tweet user user_url
And currently my SQL for insertion is as follows:
$tweet = $clean_content[0]; $user_url = $clean_uri[0]; $user = $clean_name[0]; $query='INSERT INTO hash (tweet, user, user_url) VALUES ("'.$tweet.'", "'.$user.'", "'.$user_url.'")'; mysql_query($query);
How to properly use "INSERT ... ON DUPLICATE KEY UPDATE" to insert only if it does not exist and is updated if it does?
thanks
source share