Reputation: 15
I am building a web-scraper which pulls data from websites and store it in database table . Primary key of the table is {timestamp+websitename} . Where timestap taken from that website . This happen in every 30 mins .
There are two possiblities a) I pulled the same data gain b) The content got edited on that website but still primary key remain same since creation time (timestap of this post) and website name remain unchanged.
Now I don't want to check using PHP weather same primary key exist or not. I just want data to get pushed into the database without giving me integrity constrain error . I want to do it for efficiency . Is there a way to do it in Mysql ? .
In simple words if row with same primary key already exist simply replace it with the current without throwing integrity constrain at me .
Upvotes: 0
Views: 303
Reputation: 29907
Yes, with REPLACE INTO statements.
A nice summary and caveats are described here
Upvotes: 2
Reputation: 11829
if you use simple insert, take a look: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
Upvotes: 0