Inserting NOW() into Database with CodeIgniter's Active Record

后端 未结 11 1032
傲寒
傲寒 2020-12-01 02:15

I want to insert current time in database using mySQL function NOW() in Codeigniter\'s active record. The following query won\'t work:

$data = array(
                


        
11条回答
  •  Happy的楠姐
    2020-12-01 03:02

    putting NOW() in quotes won't work as Active Records will put escape the NOW() into a string and tries to push it into the db as a string of "NOW()"... you will need to use

    $this->db->set('time', 'NOW()', FALSE); 
    

    to set it correctly.

    you can always check your sql afterward with

    $this->db->last_query();
    

提交回复
热议问题