mysql存在则更新,不存在则插入,请教要如何写

WBOY
Release: 2016-06-13 10:18:18
Original
849 people have browsed it

mysql存在则更新,不存在则插入,请问要怎么写
mysql存在则更新,不存在则插入,请问要怎么写
如一个记录对好友评价的表
friend_id comment_num
当该条数据存在时,直接更新,不存在,则先插入,请问怎么做,谢谢

------解决方案--------------------

PHP code
REPLACE INTO `table` (friend_id,comment_num)VALUES(...);<br><font color="#e78608">------解决方案--------------------</font><br>如果表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有相同的值,则在新记录被插入之前,旧记录被删除<br>除非表有一个PRIMARY KEY或UNIQUE索引,否则,使用一个REPLACE语句没有意义。<br>
Copy after login
探讨

PHP code
REPLACE INTO `table` (friend_id,comment_num)VALUES(...);
记录存在 修改,不存在插入
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!