I search through the net but i didn't find any solution, My problem is that how do I now during update that if a row values has changed or not or if a row is affected?
use affected_rows();
$this->db->affected_rows()
Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).
When we are working with CodeIgniter, the data is only updated when there is some change in the input field's value and then the $this->db->affected_rows() will return a value greater than 0.
Suppose we have two fields, 'name' and 'email'. If we try to submit the form without changing any of the field, then $this->db->affected_rows() will return 0, else it will return 1.
A better approach is to use:
if ($this->db->affected_rows() >= 0) {
return true; // your code
} else {
return false: // your code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With