• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
affected_rows results to 0 if Active Record update data is the same

#1
[eluser]rvillalon[/eluser]
I understand that the affected_rows returns 0 if the data being updated is the same. Is there an alternative to affected_rows to tell me that it still found the row even though it didn't update it because it was the same data?

Code:
/**
     * Updates entire user settings
     *
     * @param    int
     * @param    array
     * @return    object
     */
    function update_user_by_id($id, $data)
    {
        $this->db->where('user_id', $id);
        $this->db->update($this->user_profile_table_name, $data);
        
        if ($this->db->affected_rows() > 0) return TRUE;
        return FALSE;
    }

#2
[eluser]rvillalon[/eluser]
I just found the following code on codeigniter that might solve my problem:

$this->db->set('column', 'value');
$result = $this->db->update('table');
if (!$result)
{
// there was an error
}
else if (!$this->db->affected_rows())
{
// no error, but nothing changed
}
else
{
// record changed
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.