views:

185

answers:

1

I have the following private method in my form :

    function _verifywebsite ($id) {
 $row = $this->websites->fetchRow("id=$id");
 $row->verified_date = $this->_get_date(); // this is the line in question
 $row->save();
}

I assume that $row requires me to enter date as string value in correct date format.

But what if I want to include some SQL function, like NOW(), can I assign it to $row->verified_date somehow or it's against best practices?

+8  A: 

This code is enabling SQL expression for Active Record field:

$row->verified_date = new Zend_Db_Expr('now()');

As ZF Manual says:

You might need values in the data array to be treated as SQL expressions, in which case they should not be quoted. By default, all data values passed as strings are treated as string literals. To specify that the value is an SQL expression and therefore should not be quoted, pass the value in the data array as an object of type Zend_Db_Expr instead of a plain string.

PHP thinker
This is the best way :)
David Caunt