SQL NOW () gives 0000-00-00 00:00:00

I performed an SQL insert using NOW () using codeigniter. instead of the current time, I got a 00:00:00 0000-00-00 in my db recode. I use the latest WAMP as my server and cannot figure out where the problem is. please help me.

function createform($form_data)
{
    $this->db->set('created', 'NOW()',TRUE);
    $this->db->insert('amfbases', $form_data);

    if ($this->db->affected_rows() == '1')
    {
        return TRUE;
    }

    return FALSE;
}
+3
source share
2 answers

check the column data type and you specified NOW (), for example insert into table values ("NOW()");?

updated

$this->db->set('created', time(),TRUE);

or

$this->db->set('created', date('Y-m-d H:i:s'),TRUE);

or update the table schema to add_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

updated 2

NOW() points to MYSQL, PHP interprets it as a string and cannot mix both together

+6
source

(.. sql- db) - FALSE :

$this->db->set('created', 'NOW()', FALSE); // notice FALSE

, codeigniter , sql .

:

$this->db->set('counter', 'counter + 1', FALSE);

: http://codeigniter.com/user_guide/database/active_record.html

+1

Source: https://habr.com/ru/post/1774718/


All Articles