user7171965
user7171965

Reputation: 1

Check if any cell was really changed by update (mysql, php)

I have an update query in my code - and I want to check if this update REALLY changed any cell - when I try mysqli_affected_rows() - it returns to me that rows were affected/changed, even if they werent.

f.e. when I update value 'test' to the same value 'test' -> it shows me that the row was changed, but I only want to know when it was relly changed (when different value was updated)

How can I achieve that? I'm using mysql and php

Upvotes: 0

Views: 293

Answers (1)

bcmcfc
bcmcfc

Reputation: 26825

Dirty checking is one such strategy. It involves doing the check before you write to the database. This avoids unnecessary round trips to the database.

Process is as follows:

  • retrieve record from database
  • set new value only if new value != original value
  • mark the record as "dirty" if the value was changed

Once all sets have been applied, if the record is dirty, save it.

Upvotes: 1

Related Questions