Welcome Guest, Not a member yet? Register   Sign In
Issues with $this->db->insert
#1

[eluser]awpti[/eluser]
Code:
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?
#2

[eluser]champs[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB