MySQL - 可以'INSERT INTO - ON DUPLICATE KEY UPDATE'导致数据丢失

时间:2023-01-20 16:32:37

I have a caching script that requests a bunch of data from a SOAP API using PHP (Cron job every 5 minutes). This script requests and stores a customer id and name.

我有一个缓存脚本,它使用PHP(每5分钟一次Cron作业)从SOAP API请求一堆数据。此脚本请求并存储客户ID和名称。

The table that the API information is stored in has 3 columns:

存储API信息的表有3列:

'id' = int, Primary_key
'name' = varchar(255)
'paying' = bool

There is around 10 (in 80) customers with the bool paying set to true. However, every once in a while the all customer's paying columns revert to 0.

有大约10个(80个)客户将bool支付设置为true。但是,每隔一段时间,所有客户的付费列都会恢复为0。

So... Can the following query cause the paying column to change under any circumstances?

那么......以下查询是否会导致付费列在任何情况下都发生变化?

INSERT INTO customer(`id`, `name`) VALUES ('$escapedId','$escapedName') ON DUPLICATE KEY UPDATE `name`='$escapedName'

1 个解决方案

#1


1  

This query couldn't change the 'paying' field state.

此查询无法更改“付费”字段状态。

Therefore, most likely the reason is some other code that is either setting the value to 0, or just deleting all records.

因此,最有可能的原因是某些其他代码要么将值设置为0,要么只是删除所有记录。

#1


1  

This query couldn't change the 'paying' field state.

此查询无法更改“付费”字段状态。

Therefore, most likely the reason is some other code that is either setting the value to 0, or just deleting all records.

因此,最有可能的原因是某些其他代码要么将值设置为0,要么只是删除所有记录。