Zend_Db_Expr('NOW()')和Mysql中的日期时间

时间:2012-05-16 10:42:22

标签: mysql zend-framework datetime zend-db-table

所以我在实时网站上遇到了一个奇怪的问题,我不确定是什么导致了这个问题,因为在mysql表的datetime字段中,有时会映射时间,而且往往不是。但是始终映射日期。

代码是这样的:

   $party_system_id = $this->blabla->addUser($username, 'None', 'None', '',
   $email,$promo_code,$distributor_id);

    if ($party_system_id!=0){

    $loginToken = md5(uniqid(rand(), true));    

        $params = array(
            'sponsorId' => $sponsor_id,
            'refferalId' => $referral_id,
            'accountType' => $type,
            'email' => $email,
            'username' => $username,
            'password' => md5($password),
            'firstName' => 'n/a',
            'lastName' => 'n/a',
            'expires' => $expiration_date,
            'activated' => 1,
            'gender' => $gender,
            'languageId' => 38,
            'onlineStatus'=> 0,
            'status' => 5,
            'dateAdded' => new Zend_Db_Expr('NOW()'),
            'blaId' => $party_system_id,
    'loginToken' => $token,
            'termsAccepted' => 1
        );

        return $this->insert($params);

    }

注册总是很好,但就像我说的那样,很多用户都说: 2012-05-16 10:20:33 我会得到: 2012-05-16 00:00:00 当然不是00:00:00在注册时:)

我不确定可能是什么问题,mysql,脚本结构或Zend_Db_Expr。我也不知道如何正确调试这个,但所有建议都更受欢迎:)

1 个答案:

答案 0 :(得分:1)

确保dateAdded字段确实有Y-m-d H:i:s作为格式, 但您也可以使用date('Y-m-d H:i:s')

  $params = array(
        'sponsorId' => $sponsor_id,
        'refferalId' => $referral_id,
        'accountType' => $type,
        'email' => $email,
        'username' => $username,
        'password' => md5($password),
        'firstName' => 'n/a',
        'lastName' => 'n/a',
        'expires' => $expiration_date,
        'activated' => 1,
        'gender' => $gender,
        'languageId' => 38,
        'onlineStatus'=> 0,
        'status' => 5,
        'dateAdded' => date('Y-m-d H:i:s'),
        'blaId' => $party_system_id,
        'loginToken' => $token,
        'termsAccepted' => 1
    );