too long

I know it is a frequently asked question, but let me explain a bit why I need to ask that again.

Most answers out there suggests using

$this->db->affected_rows()

This is not working in my situation as I may have situation that the update data is the same as the data in the database, so it will return 0 even if the update is success.

I know I can write another query to check if it is because the data are the same, but this sounds stupid to me.

Another way is to use the Active Record Class in code igniter, so the line will be something like:

$error_num = $this->db->update("users", array('firstName' => $newFirstName));
return $error_num;

which is a better solution (at least it works even if there is no update due to repeated data). However, I would like to use the database class, i.e. something like:

$this->db->query('update table set field = somedata where id=1');

It increases the readability of my code to coder who knows php + SQL but are not familiar with code igniter, but then this is why I am asking if anybody knows how do I get the error number if I query in this way?

i.e. Something like mysql_errno() when using mysql_query($query) in PHP.

Both will work like same only difference

if you using active record class all the input variables are escaped automatically

If you want security you better to go with active record class

If you use normal query execution you have to escape the input parameters manually using $this->db->escape_str()

  $id = $this->db->escape_str($id)

You can check the query execution status.

$status =  $this->db->update("users", array('firstName' => $newFirstName));

if($status)
{
    //here you can check the number of affected rows if required
    echo $this->db->affected_rows();

}else{

      //here you can prcess for failure case
      log_message('Error', $this->db->_error_message());

}

//return the status to required place
return $status

I have use this code for checking.

$status = $this->db->query('update table set field = somedata where id=1'); 
if($status)
   return true;
else
    return false;