John Hoffman John Hoffman - 8 months ago 35
MySQL Question

How do I test if my MySQL update query was successful in Code Igniter?

I have a model function that updates a user in my Code Igniter 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
has been updated? For instance, it should return false if no user was found with ID


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

That will tell you how many rows were updated.