简体   繁体   中英

PHP PDO Update Query not working

I am PDO newbie and i dont know how to catch error's or see what wrong anyway look at this code :

Call The Function here :

   $this->storage->updateTriplet($cookieValues[0],$newToken.$this->salt, $cookieValues[2].$this->salt, $t, $expire);

The problem function :

   public function updateTriplet($credential, $token, $persistentToken,$t, $expire=0) {
        $sql = "UPDATE {$this->tableName}
        SET cred=?, tok=?, ptok=?, t=?, expires=? 
        WHERE ptok=?'".$persistentToken."' ";
    $query = $this->connection->prepare($sql);
    $query->execute(array($credential ,$token, $persistentToken , $t , date("Y-m-d H:i:s", $expire)));
  }

And that the good function ,insert function i using :

    public function storeTriplet($credential, $token, $persistentToken,$t, $expire=0) {
    $sql = "INSERT INTO {$this->tableName}({$this->credentialColumn}, " .
           "{$this->tokenColumn}, {$this->persistentTokenColumn}, " .
           "{$this->t},{$this->expiresColumn}) VALUES(?, SHA1(?), SHA1(?),?, ?)";
    $query = $this->connection->prepare($sql);
    $query->execute(array($credential, $token, $persistentToken,$t, date("Y-m-d H:i:s", $expire)));
  }

Anyway my insert function working perfect the problem is on the Update Function first one ,my update function not working , any one know where is my problem and what i am doing wrong ? and how to see the MySql PDO error's on the Update Function ?

Updated : answered and fix :

   public function updateTriplet($credential, $token, $persistentToken,$t, $expire=0) {
        $sql = "UPDATE {$this->tableName}
        SET cred=?, tok=?, ptok=?, t=?, expires=? 
        WHERE ptok=SHA1('".$persistentToken."');
    $query = $this->connection->prepare($sql);
    $query->execute(array($credential ,$token, $persistentToken , $t , date("Y-m-d H:i:s", $expire)));
  }

Thanks so much.

It seems that you missed to provied ptok parameter.

$sql = "UPDATE {$this->tableName}
        SET cred=?, tok=?, ptok=?, t=?, expires=? 
        WHERE ptok=?";

$query->execute(array($credential ,$token, $persistentToken , 
        $t , date("Y-m-d H:i:s", $expire), $ptok));
                                           // ^______ Add this variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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