how to do this with pure mysql?
If mysql record with condi开发者_如何学Ction exists-update it,else create new record
Is this what you're looking for?
INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
You can use the REPLACE INTO
for that with the syntax of INSERT INTO
. This way MySQL will invoke an UPDATE
whenever there's a fictive constraint violation.
Be aware that this construct is MySQL-specific, so your query ain't going to work whenever you switch from DB.
Use REPLACE instead of INSERT.
Are you looking for INSERT ... ON DUPLICATE KEY UPDATE
?
精彩评论