我是PDO新手,我不知道如何捕捉错误或者看看错误无论如何看这段代码:
在此处调用此函数:
$this->storage->updateTriplet($cookieValues[0],$newToken.$this->salt, $cookieValues[2].$this->salt, $t, $expire);
问题功能:
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)));
}
那个好的功能,插入功能我使用:
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)));
}
无论如何我的插入功能完美问题出在Update Function第一个,我的更新功能不起作用,任何人都知道我的问题在哪里以及我做错了什么?以及如何在更新功能上看到MySql PDO错误?
更新:已解答并修复:
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)));
}
非常感谢。
答案 0 :(得分:1)
您似乎错过了提供ptok
参数。
$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