1 2 3 4 5 6 7 8 |
if ($this->db->affected_rows() > 0) { return TRUE; } else { return FALSE; } |
or
1 2 3 4 |
if ($this->db->affected_rows() > 0) return TRUE; else return FALSE; |
or
1 |
return ($this->db->affected_rows() > 0) ? TRUE : FALSE; |
also(much better)
1 |
return ($this->db->affected_rows() > 0); |
A better solution I’ve found is to manage the difference between an ERROR and 0 affected rows. 0 affected rows is not necessarily a bad thing, but an error is something you do want to know about:
1 2 3 4 5 |
if ($this->db->_error_message()) { return FALSE; // Or do whatever you gotta do here to raise an error } else { return $this->db->affected_rows(); } |
Now your function can differentiate…
1 2 3 4 5 6 7 |
if ($result === FALSE) { $this->errors[] = 'ERROR: Did not update, some error occurred.'; } else if ($result == 0) { $this->oks[] = 'No error, but no rows were updated.'; } else { $this->oks[] = 'Updated the rows.'; } |
Just some quick hacking there – you should obviously make the code far more verbose if you have other people using it.
The point is, consider using _error_message to differentiate between 0 updated rows and a real problem.