How do I tell when a MySQL UPDATE was successful versus actually updated data? How do I tell when a MySQL UPDATE was successful versus actually updated data? codeigniter codeigniter

How do I tell when a MySQL UPDATE was successful versus actually updated data?


Have a look at mysql_affected_rows()

It should tell you if anything was actually updated as opposed to nothing was successfully updated resulting in a return of true.

php.net says:

mysql_affected_rows()

Returns the number of affected rows on success, and -1 if the last query failed.

You could use the following to achieve your desired results:

if($this->db->affected_rows() >= 0){ }


Then you would use mysql_query:

SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

Simple like this:

$result = $this->db->update('table', $data);if($result){     //without error even no row updated} else {}