If mysql exists, it is updated. if mysql does not exist, it is inserted. how can this problem be written?

Source: Internet
Author: User
If mysql exists, it is updated. if it does not exist, it is inserted. how can I write it? if mysql exists, it is updated. if it does not exist, it is inserted, how can I write a table like friend_idcomment_num, which records comments on Friends? when this data exists, it is directly Updated. if it does not exist, insert it first. what can I do? thank you, PHPcodeREPLACE mysql is updated if it exists. if it does not exist, it is inserted. how can I write it?
Mysql is updated if it exists. if it does not exist, it is inserted. how can I write it?
Such as a table that records comments on friends
Friend_id comment_num
If this data entry exists, it is directly Updated. if it does not exist, insert it first. how can this problem be solved? thank you.

------ Solution --------------------
PHP code
Replace into 'Table' (friend_id, comment_num) VALUES (...);
------ Solution --------------------
If an old record in the table has the same value as a new record used for the primary key or a UNIQUE index, the old record is deleted before the new record is inserted.
Unless the table has a primary key or UNIQUE index, it makes no sense to use a REPLACE statement.
Discussion

PHP code
Replace into 'Table' (friend_id, comment_num) VALUES (...);
Record modified and inserted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.