Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78ab196

Browse files
committed
* Fixed PDOStatement exception "SQLSTATE[HY093]: Invalid parameter number " in putOffExpiration()
* Explicit casting Key to string in getHashedKey()
1 parent 7377265 commit 78ab196

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ public function putOffExpiration(Key $key, $ttl)
164164

165165
$key->reduceLifetime($ttl);
166166

167-
$sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + $ttl, $this->tokenCol = :token WHERE $this->idCol = :id AND ($this->tokenCol = :token OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
167+
$sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + $ttl, $this->tokenCol = :token1 WHERE $this->idCol = :id AND ($this->tokenCol = :token2 OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
168168
$stmt = $this->getConnection()->prepare($sql);
169169

170+
$uniqueToken = $this->getUniqueToken($key);
170171
$stmt->bindValue(':id', $this->getHashedKey($key));
171-
$stmt->bindValue(':token', $this->getUniqueToken($key));
172+
$stmt->bindValue(':token1', $uniqueToken);
173+
$stmt->bindValue(':token2', $uniqueToken);
172174
$stmt->execute();
173175

174176
// If this method is called twice in the same second, the row wouldn't be updated. We have to call exists to know if we are the owner
@@ -214,7 +216,7 @@ public function exists(Key $key)
214216
*/
215217
private function getHashedKey(Key $key): string
216218
{
217-
return hash('sha256', $key);
219+
return hash('sha256', (string)$key);
218220
}
219221

220222
private function getUniqueToken(Key $key): string

0 commit comments

Comments
 (0)