0
votes

I have to update a user in my DB. It validates and goes through all the code perfectly, but it does not change it in the DB. This leads me to conclude that the problem is with my query.

public function edit_user($data, $users_id) {
    $this->db->set('updated_at', 'NOW()', FALSE);
    return $this->db->update('users', $data, array('id' = > $users_id));
}

I have no idea why its not working.

3
What is the error you're getting, try changing the tablename users(wrong tablename) to something else and you can see the query on the browser - Satish Ravipati

3 Answers

1
votes

Try this:

public function edit_user($data, $users_id)
{
    $this->db->set('updated_at', date('Y-m-d H:i:s'), FALSE);
    return $this->db->update('users', $data, array('id' => $users_id));
}

Instead of updating current date You can change database column settings 'updated_at' - set on update current_timestamp.

0
votes
public function edit_user($data, $users_id)
{
    $this->db->set('updated_at', 'NOW()', FALSE);
    $this->db->where('id', $users_id);
    return $this->db
                ->update('users', $data);
}
0
votes

You can also try like

public function edit_user($data, $users_id)
{
    $data['updated_at'] = date('Y-m-d H:i:s');
    return $this->db->update('users', $data, array('id' => $users_id));
}