我是 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)));
}
无论如何,我的插入功能完美运行,问题出在第一个更新功能上,我的更新功能不起作用,有人知道我的问题在哪里以及我做错了什么吗?以及如何在更新功能上查看 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)));
}
非常感谢。