Reputation: 9044
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?
Upvotes: 4
Views: 8340
Reputation: 939
I think this is the simplest way to achieve this goal.
return ($this->db->affected_rows() != 1) ? false : true;
Upvotes: 0
Reputation: 516
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
}
Upvotes: 3
Reputation: 36531
use affected_rows()
;
$this->db->affected_rows()
Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).
Upvotes: 8