EllisLab text mark
Advanced Search
     
Issues with $this->db->insert
Posted: 05 July 2007 12:13 PM   [ Ignore ]
Avatar
Joined: 2002-11-11
180 posts
function comments_insert() {
    $this
->db->insert('awNewsComments'$_POST);
    
redirect('/comments/'.$_POST['comments_news_id'].'/');

Taken from the sample blog tutorial.

Does db->insert not kick off a NOW() function on DATETIME fieldtypes?  Seems to always leave the value NULL.

Is there a way to get it to fire off NOW(), or do I need to format a string to pass with it?

 Signature 

Blog:
GeekLAN
Projects:
Ignited Jobs - LAMP Tips

 
Posted: 05 July 2007 12:48 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-25
56 posts

All strings passed to Active Record are inserted as strings, so NOW() is wrapped in quotes, just like everything else, and you will need a function that returns the date string you need.  In MySQL, you’ve got an ON UPDATE CURRENT_TIMESTAMP attribute (that you can set on ONE field, IIRC), but if you have multiple date fields, don’t bother.

And just to get out ahead of you, a special exception for NOW() means special exceptions for *every* pet function someone cares to use in their statements.

 Signature 

Join us in #codeigniter on irc.freenode.net