MYSQL / PHP中只有一个datetime列正在更新

时间:2020-03-30 03:34:49

标签: php mysql

我在users表中有两个datetime字段,默认都没有。当我尝试更新时,只有一个正在更新。

if($user_password==$oldpassword){
    $connection = Yii::app()->db;
    $updateUser = $connection->createCommand()->update('users',array('user_password'=>$confirmpassword,
        'modifiedtime'=>$dttime,
        'password_changed_at'=>$dttime),
        'id=:recordid',
        array('recordid'=>$recordid));
    echo"1";

}

modifiedtime列正在更新,但password_changed_at列未更新。有什么建议?谢谢

这是完整的代码;

public function changepassworduser(){
    $encryptDecrypt=new EncryptDecrypt;
    $enc_old_password = $_POST['oldpassword'];
    $enc_new_password = $_POST['newpassword'];
    $enc_confirm_password = $_POST['confirmpassword'];
    //$publickey = $encryptDecrypt->getPublicKey();
    $publickey = $_POST['publickey'];
    $dec_old_Pass=$encryptDecrypt->cryptoJsAesDecrypt($publickey, $enc_old_password);
    $dec_new_Pass=$encryptDecrypt->cryptoJsAesDecrypt($publickey, $enc_new_password);
    $dec_confirm_Pass=$encryptDecrypt->cryptoJsAesDecrypt($publickey, $enc_confirm_password);
    $oldpassword = md5($dec_old_Pass);
    $confirmpassword = md5($dec_new_Pass);

    $recordid   = (int)$_POST['recordid']; 
    if($recordid=='00'){
        $siteDir=Yii::app()->params['dirName'];
        $recordid   = (int)$_SESSION[$siteDir."_id"];
    }else{
        $recordid   = (int)$_POST['recordid'];
    }
    $connection = Yii::app()->db;

    $query  = "select user_password,first_name,user_hash from users where id=:id"; 
    $command    = $connection->createCommand($query);
    $command->bindParam(":id",$recordid,PDO::PARAM_INT);
    $Column     = $command->queryRow();
    $user_password  = $Column['user_password'];
    $user_hash      = $Column['user_hash'];
    $first_name     = $Column['first_name'];
    $dttime     = date('Y-m-d h:i:s');
    if($user_password==$oldpassword){
        $connection = Yii::app()->db;
        $updateUser = $connection->createCommand()
            ->update('users',array('user_password'=>$confirmpassword,'user_hash'=>$confirmpassword,'modifiedtime'=>$dttime,'password_changed_at'=>$dttime),'id=:recordid',array('recordid'=>$recordid));
        echo"1";

    }else{
        echo"10";
}

}

这些是表格的某些列

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `fyear` int(2) NOT NULL,
  `user_password` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
  `user_hash` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
  `first_name` varchar(30) CHARACTER SET latin1 DEFAULT NULL,
  `last_name` varchar(30) CHARACTER SET latin1 DEFAULT NULL, 
  `createdtime` datetime NOT NULL,
  `modifiedtime` datetime NOT NULL,
  `password_changed_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_user_name_idx` (`user_name`),
  KEY `user_user_password_idx` (`user_password`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=244 ;

0 个答案:

没有答案