如何在codeigniter中使用列集NULL更新表

i have a problem with update column with set data to NULL, i have a table user with each one column is id_parent column, user can delete parent and can add parent, so if user have a parent, id_parent will set with user's parent id , but user can delete parent's data, so if user delete parent's data, id_parent column, will set to NULL. so how to set data to null in database not " " but NULL. here's my user table.

user

id_user | name | address | id_parent

Your user table must have the attribute set to is_null in the id_parent field. Otherwise you can't.

The query should be something like

Update table user set id_parent = null where id_user = X

You can set that column nullable with this query:

ALTER TABLE user MODIFY id_parent int(11) null;

Try this for codeigniter:

$fields = array(
                        'id_parent' => array(
                                                         'name' => 'id_parent',
                                                         'type' => 'INT',
                                                ),
);
$this->dbforge->modify_column('user', $fields);

or simply:

$this->db->query('ALTER TABLE user MODIFY id_parent int(11) null;');

you can try this code in 'model', hope it'll work:

public function update_std_marks($id_user) {

    $this->db->set('id_parent', null);
    $this->db->where('id_user', $id_user);
    $this->db->update('user');
}

use this to set null column.it will work, dont forget add false on third parameter SET on active record

$this->db->set('id_parent', 'NULL', false);