Welcome Guest, Not a member yet? Register   Sign In
NULL inserting as 0 ?
#1

[eluser]iDVB[/eluser]
In my code below I'm setting $description default to NULL but in the MySQL db field it gets inserted as 0 even thought that field defaults to NULL and allows NULL.

Code:
function create($title, $description = NULL, $user_id = false)
    {
        $response = array();
        $user_id = $user_id ? $user_id : $this->_user_id;
        
        $data = array(
                        'title'         => $title,
                        'description'     => $description,
                        'user_id'        => $user_id,
                        'cdate'         => date("Y-m-d H:m:s", time())
                    );
        $this->db->insert('trackGroups', $data);
        $response = $this->db->insert_id();
        
        return $response;
    }
#2

[eluser]jayrulez[/eluser]
[quote author="iDVB" date="1251528640"]In my code below I'm setting $description default to NULL but in the MySQL db field it gets inserted as 0 even thought that field defaults to NULL and allows NULL.

Code:
function create($title, $description = NULL, $user_id = false)
    {
        $response = array();
        $user_id = $user_id ? $user_id : $this->_user_id;
        
        $data = array(
                        'title'         => $title,
                        'description'     => $description,
                        'user_id'        => $user_id,
                        'cdate'         => date("Y-m-d H:m:s", time())
                    );
        $this->db->insert('trackGroups', $data);
        $response = $this->db->insert_id();
        
        return $response;
    }
[/quote]

try this

Code:
function create($title, $description = "", $user_id = false)
#3

[eluser]iDVB[/eluser]
Nope, still gets input as a 0.

My field type is "text" and NULL is allowed and the default is NULL.


Maybe the question I should be asking is...what should one use as a field type for a "description" field in a MySQL DB. Also, what should be stored in the DB in the case that there is no description? Eg. "" or NULL or 0




Theme © iAndrew 2016 - Forum software by © MyBB