Inserting NOW() into Database with CodeIgniter's Active Record
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);
Unless I am greatly mistaken, the answer is, "No, there is no way."
The basic problem in situations like that is the fact that you are calling a MySQL function and you're not actually setting a value. CI escapes values so that you can do a clean insert but it does not test to see if those values happen to be calling functions like aes_encrypt
, md5
, or (in this case) now()
. While in most situations this is wonderful, for those situations raw sql is the only recourse.
On a side, date('Y-m-d');
should work as a PHP version of NOW()
for MySQL. (It won't work for all versions of SQL though).
aspirinemaga, just replace:
$this->db->set('time', 'NOW()', FALSE);$this->db->insert('mytable', $data);
for it:
$this->db->set('time', 'NOW() + INTERVAL 1 DAY', FALSE);$this->db->insert('mytable', $data);