开发者

How to store timestamp in db with Zend_Date?

I keep trying to insert a timestamp to the db with $rowUser->fecha = new Zend_Date(); but when I check the db I always find '0000-00-00 00:00:00' in that field.

I added the 'fecha' column (the one with the timestamp) with a MySQL ALTER开发者_JS百科 statement, so maybe that's the prolem...I don't know. Not sure if it's my zend or SQL which is failing. Please Mods, don't close the thread if the question seems vague, I'll change or look for more info if necessary.


Well for whoever may care about this or may have a similar issue in the future I've found a way around this. In the user model:

$rowUser = $this->createRow();

    if($rowUser) {
        // update the row values
        $rowUser->email = $email;
        $rowUser->password = md5($password);
        $rowUser->url = $url;
        $rowUser->responsable = $responsable;
        $rowUser->role = $role;
        $rowUser->fecha = Zend_Date::now()->toString('yyyyMMddHHmmss');; // This is the important bit
        $rowUser->save();
        //return the new user
        return $rowUser;
    } 

you could also use $rowUser->fecha = new Zend_Db_Expr('NOW()'); but that might be troublesome if there's a db migration.


I believe you'll need to use something similar to

$rowUser->fecha = new Zend_Db_Expr('NOW()');

I think you can use the Zend_Date component, but you'll have to convert it to the correct format as a string representation to insert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜