mysql update or insert

 The two SQLs have similar effects, but the essential difference is that the above is an update, and the bottom is an insert after deletion, which can be used to reduce the amount of code and improve efficiency when updating or inputting.

The rule is that when the primary key or the unique index overlaps, the update or delete insert is suitable for combining the unique index.

$sql = 'INSERT INTO `'.$tableg.'` ('.$field['str1'].') VALUES ('.$field['str2'].')  ON DUPLICATE KEY UPDATE `user_id`=VALUES(user_id),`ymd`=VALUES(ymd)';
$sql = 'REPLACE INTO `'.$tableg.'` ('.$field['str1'].') VALUES ('.$field['str2'].')';

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325939124&siteId=291194637