CodeIgniter Forums
Active record and NULL value ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active record and NULL value ? (/showthread.php?tid=4898)



Active record and NULL value ? - El Forum - 12-21-2007

[eluser]ariok[/eluser]
Hi all,
I found this problem working with active record:
What i have to do if i need to insert a NULL value in my DB ?

if i have array data with:
"fieldone"=>"this value",
"fieldtwo"=>null

the query generated with $this->db->insert($array)... is something like:

Code:
(fieldone,fieldtwo) values ("this value",[b]"null"[/b])

But i want a query like

Code:
(fieldone,fieldtwo) values ("this value",[b]null[/b])

with null and not "null"....

there's a pratical way to obtain the second query instead first?

Thank you all ..

Ariok


Active record and NULL value ? - El Forum - 12-21-2007

[eluser]easymind[/eluser]
I don't think so. I had the same problem with TIMESTAMP=NOW(). I don't want "NOW()". So I just use normal queries and no active record for these. Like $this->db->query('INSERT INTO thingy SET yours=null and mine=NOW()');

It is a damn shame Smile But I am guessing it is also hard to fix without using an alternative way to syntax the variables you send to the active record class.

By the way, did you try:
'fieldtwo'=>''
or
'fieldtwo'=>false?

I think it should save the default value for that column in your mysql table and that probably is set to NULL?


Active record and NULL value ? - El Forum - 12-22-2007

[eluser]ariok[/eluser]
ops... i wrong something Tongue
I have to say that i i use this array

"fieldone"=>"this value",
"fieldtwo"=>null

I obtain:

(fieldone,fieldtwo) values ("this value",null) without ""

So it's all ok ....sorry.