How to update table with column set NULL in codeigniter
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);
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');}
I was curious so I wanted to see how CodeIgniter's Active Record would handle different variations of syntax when working with a null value. I'll map out several test cases for where()
and set()
method calls.
Battery of where()
tests:
->where('col', null) // `col` IS NULL
->where('col', null, false) // col IS NULL
->where('col', 'NULL') // `col` = 'NULL'
->where('col', 'NULL', false) // col = NULL
->where('col IS NULL') // `col` IS NULL
->where('col IS NULL', null) // `col` IS NULL
->where('col IS NULL', null, false) // col IS NULL
->where('col', 'IS NULL') // `col` 'IS NULL'
->where('col', 'IS NULL', false) // col = IS NULL
Properly quoted and formed: #1, #5, #6 (recommended)
Logically formed, but not quoted: #2, #7 (not recommended)
Inappropriate rendered syntax: #3, #4, #8, #9 (do not use)
Battery of set()
tests:
->set('col', null) // `col` = NULL
->set('col', null, false) // col =
->set('col', 'NULL') // `col` = 'NULL'
->set('col', 'NULL', false) // col = NULL
->set('col IS NULL') // `col IS` `NULL` = ''
->set('col IS NULL', null) // `col IS` `NULL` = NULL
->set('col IS NULL', null, false) // col IS NULL =
->set('col', 'IS NULL') // `col` = 'IS NULL'
->set('col', 'IS NULL', false) // col = IS NULL
Properly quoted and formed: #1 (recommended)
Logically formed, but not quoted: #4 (not recommended)
Inappropriate rendered syntax: #2, #3, #5, #6, #7, #8, #9 (do not use)