If Only I Knew That!

Webby things that could save you time

Archive for May, 2011

Using MySQL NOW() in Codeigniter

without comments

There are two easy ways to do this

With NOW()

$data = array(
    'field_name' => 'some_data'
);
$this->db->set('date_field_name', 'NOW()', FALSE);
$this->db->insert('table_name', $data);

The FALSE in the set method prevents the NOW() being escaped

Without NOW()

$now = date('Y-m-d H:i:s');
$data = array(
    'field_name' => 'some_data',
    'date_field_name' => $now
);
$this->db->insert('table_name', $data);

Written by daveganley

May 5th, 2011 at 9:23 am

Posted in Codeigniter

Powered by CDN Rewrites