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(
'name' => $name ,
'email' => $email,
'time' => NOW()
);
$this->db->insert('mytable', $data);
This is because CodeIgniter’s ActiveRecord class automatically escapes the input.
The following works fine, by calling set() and passing peratmeter FALSE, so that it doesn't escape the NOW().
$data = array(
'name' => $name ,
'email' => $email,
);
$this->db->set('time', 'NOW()', FALSE);
$this->db->insert('mytable', $data);
However, my question is that is there any other way than this? For example, if i can use somehow use by adding everything in the data array only? For example, something like:
$data = array(
'name' => $name ,
'email' => $email,
'time' => NOW(), FALSE
);
I typically use triggers to handle timestamps but I think this may work.
$data = array(
'name' => $name,
'email' => $email
);
$this->db->set('time', 'NOW()', FALSE);
$this->db->insert('mytable', $data);