codeigniter how to know update failed
In CodeIgniter, when performing an update operation using the Active Record class, you can check if the update was successful by using the
affected_rows()
method.After executing the update query, call the
affected_rows()
method to get the number of affected rows.If the number of affected rows is greater than 0, the update was successful. If it's 0, the update failed.
Here's an example code snippet:
// Your update query using the Active Record class
$this->db->where('your_condition', 'your_value');
$this->db->update('your_table', $data);
// Check if the update was successful
if ($this->db->affected_rows() > 0) {
// Update successful
echo 'Update successful!';
} else {
// Update failed
echo 'Update failed!';
}
Replace 'your_condition', 'your_value', 'your_table', and $data with your actual update conditions, values, table name, and data array.
This method allows you to determine whether the update operation was successful or not in CodeIgniter.