doutang7415 2011-08-30 01:57
浏览 54
已采纳

Zend Framework Table插入MySQL Expression

Just wanted to ask if there is an easyer way to do this (to use the FROM_UNIXTIME expression):

$table = $this->getDbTable();
$db = $table->getAdapter();

$table->insert(array(
    'date'=>new Zend_Db_Expr($db->quoteInto('FROM_UNIXTIME(?)', time())),
    'name'=>$name,
    'password'=>'',
    'passworddate'=>'0000-00-00 00:00:00'
));

I mean it's a lot overhead just to use FROM_UNIXTIME. And it's looks not very clean in my opptinion.

  • 写回答

1条回答 默认 最新

  • dongwen7380 2011-08-30 02:01
    关注

    You can simply use MySQL's NOW() function unless there's a time difference between your application and database servers.

    'date' => new Zend_Db_Expr('NOW()'),
    

    If the application server time takes priority, why not simply try

    'date' => date('Y-m-d H:i:s'),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?