Welcome Guest, Not a member yet? Register   Sign In
Active records problem
#1

[eluser]umefarooq[/eluser]
Hi im facing one problem with CI database active record is while inserting and updating any records im sending some fields just empty , where these field default value is NULL in table when query executed successfully but it add 0 to most of fields who's value im sending empty i want Null value to be insert.
#2

[eluser]umefarooq[/eluser]
its really strange but figure out just looping the post data and checking if is empty assign NULL just a simple example

Code:
$data['content'] = ($this->input->get_post('content') == '')?NULL:$this->input->get_post('content');

but i need more good explanation
#3

[eluser]mddd[/eluser]
Inserting an empty string into a database field is different from inserting NOTHING into that field.
If you insert nothing, or you don't even specify the field at all in your INSERT query, then you will get the default value.
If you DO insert something (namely an empty string) then THAT will be inserted. (And if the field is not a text/char field, the empty string will be translated to something that does match the type, like 0).

Consider this: if you inserted an empty string into a text field and that text field had a default value, what should mysql do? Well, save the empty string of course! That is what you put in there. It won't put in a default value if you specify a value. Even if your value is an empty string, or 0.




Theme © iAndrew 2016 - Forum software by © MyBB