简体   繁体   English

PDO更新不更新数据

[英]PDO Update not updating data

I know an answer like this has been written countless amounts of time but honestly after spending about 4 hours on this, I can't seem to find whats wrong. 我知道这样的答案已经写了无数的时间,但是老实说,在花了大约4个小时之后,我似乎找不到什么错了。 My PDO Update is not updating. 我的PDO更新未更新。 It was working a few days ago and maybe I have changed something but it doesn't work at all now. 几天前它在工作,也许我已经做了一些更改,但现在根本不起作用。

 try {
     $query_update = $db->db_connection->prepare('UPDATE ghl_users SET user_last_reset_code = :user_password_reset_hash,
                                                           user_last_reset_request = :user_password_reset_timestamp
                                                           WHERE user_name = :user_name');
     $query_update->bindValue(':user_password_reset_hash', $user_password_reset_hash, PDO::PARAM_STR);
     $query_update->bindValue(':user_password_reset_timestamp', $temporary_timestamp, PDO::PARAM_STR);
     $query_update->bindValue(':user_name', $user_name, PDO::PARAM_STR);
     $query_update->execute();
}catch( PDOException $Exception ) {
   throw new MyDatabaseException( $Exception->getMessage( ) , (int)$Exception->getCode( ) );
}

all variables are set (eg when I echo it shows me the values) 所有变量都已设置(例如,当我回显它时,将显示值)

 echo $user_name. "<br />";
 echo $temporary_timestamp. "<br />";
 echo $user_password_reset_hash. "<br />";

Values are: 值是:

johndoe
2015-06-04 09:28:29
8ctkas9f3ef35jdk2k5jaeffe115j3kkdc2ae

You only need to parameterise unsafe values , $user_password_reset_hash , to stop injection. 您只需要参数化不安全的值$user_password_reset_hash即可停止注入。 You can use SQL NOW() to update 您可以使用SQL NOW()更新

Try 尝试

 try {
 $query_update = $db->db_connection->prepare('UPDATE ghl_users 
                                    SET user_last_reset_code = :user_password_reset_hash,
                                                       user_last_reset_request = NOW()
                                                       WHERE user_name = :user_name');
 $query_update->bindValue(':user_password_reset_hash', $user_password_reset_hash, PDO::PARAM_STR);
 $query_update->bindValue(':user_name', $user_name, PDO::PARAM_STR);
 if ($query_update->execute())
      {
      // success
       echo "Updated record";
     }
    else
    {
      // failure

   }



}catch( PDOException $Exception ) {
   throw new MyDatabaseException( $Exception->getMessage( ) ,  (int)$Exception->getCode( ) );
}

Also Ensure ERRMODE_EXCEPTION is set 同时确保已设置ERRMODE_EXCEPTION

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM