kgongonowdoe
kgongonowdoe

Reputation: 435

MySQL - Can 'INSERT INTO - ON DUPLICATE KEY UPDATE' cause data loss

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.

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

'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.

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'

Upvotes: 1

Views: 128

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157828

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.

Upvotes: 1

Related Questions