简体   繁体   中英

CodeIgniter Active record update not working

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.

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.

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);
}

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));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM