Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test if my MySQL update query was successful in CodeIgniter? [duplicate]

I have a model function that updates a user in my CodeIgniter application:

// updates first of a user, return true if successful, false if not.
public function updateFirstName($userId, $newFirstName) {
    $this->db->query("UPDATE users SET firstName='$newFirstName' WHERE id=$userId");
    return // whether request was successful?
}

How do I return a boolean value that ensures the user of ID $userId has been updated? For instance, it should return false if no user was found with ID $userId.

like image 409
John Hoffman Avatar asked Sep 10 '25 15:09

John Hoffman


1 Answers

As commented, have you tried $this->db->affected_rows()?

That will tell you how many rows were updated.

like image 160
ChrisK Avatar answered Sep 12 '25 03:09

ChrisK