I need to do a such thing in SQL but I don't know how...
IF *row exists* THEN
UPDATE ...
ELSE
CREATE ...
I can't figure how to do that..
I need to do a such thing in SQL but I don't know how...
IF *row exists* THEN
UPDATE ...
ELSE
CREATE ...
I can't figure how to do that..
INSERT ... ON DUPLICATE KEY UPDATE.... or REPLACE should do the trick:
ON DUPLICATE KEY UPDATE http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
INSERT INTO lang (ip, lang) VALUES('$ip', 'fr') ON DUPLICATE KEY UPDATE lang='fr'. This also requires a collision of the unique keys on the table. What's your table structure look like?You can use a normal insert statement with a ON DUPLICATE KEY UPDATE described in the docs :