Home >Backend Development >PHP Tutorial >mysql中怎么把insert和update写成一个函数以便多次调用?

mysql中怎么把insert和update写成一个函数以便多次调用?

WBOY
WBOYOriginal
2016-06-06 20:22:411295browse

目的是多次调用并提高代码质量。注意:此处不同于类的封装。

回复内容:

目的是多次调用并提高代码质量。注意:此处不同于类的封装。

prepare statement或者stored procedure

使用insert on duplicate key
INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

Statement:
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