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

Skip to content

Commit 90752a2

Browse files
committed
Don't use named params as MySQLi doesn't support them
1 parent 477e843 commit 90752a2

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* To ensure locks don't expire prematurely; the TTLs should be set with enough
3232
* extra time to account for any clock drift between nodes.
3333
*
34+
* CAUTION: The queries in this class must not use named params
35+
* because the mysqli driver does not support them.
36+
*
3437
* @author Jérémy Derussé <[email protected]>
3538
*/
3639
class PdoStore implements StoreInterface
@@ -116,11 +119,11 @@ public function save(Key $key)
116119
{
117120
$key->reduceLifetime($this->initialTtl);
118121

119-
$sql = "INSERT INTO $this->table ($this->idCol, $this->tokenCol, $this->expirationCol) VALUES (:id, :token, {$this->getCurrentTimestampStatement()} + $this->initialTtl)";
122+
$sql = "INSERT INTO $this->table ($this->idCol, $this->tokenCol, $this->expirationCol) VALUES (?, ?, {$this->getCurrentTimestampStatement()} + $this->initialTtl)";
120123
$stmt = $this->getConnection()->prepare($sql);
121124

122-
$stmt->bindValue(':id', $this->getHashedKey($key));
123-
$stmt->bindValue(':token', $this->getUniqueToken($key));
125+
$stmt->bindValue(1, $this->getHashedKey($key));
126+
$stmt->bindValue(2, $this->getUniqueToken($key));
124127

125128
try {
126129
$stmt->execute();
@@ -158,13 +161,13 @@ public function putOffExpiration(Key $key, $ttl)
158161

159162
$key->reduceLifetime($ttl);
160163

161-
$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()})";
164+
$sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + $ttl, $this->tokenCol = ? WHERE $this->idCol = ? AND ($this->tokenCol = ? OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
162165
$stmt = $this->getConnection()->prepare($sql);
163166

164167
$uniqueToken = $this->getUniqueToken($key);
165-
$stmt->bindValue(':id', $this->getHashedKey($key));
166-
$stmt->bindValue(':token1', $uniqueToken);
167-
$stmt->bindValue(':token2', $uniqueToken);
168+
$stmt->bindValue(1, $uniqueToken);
169+
$stmt->bindValue(2, $this->getHashedKey($key));
170+
$stmt->bindValue(3, $uniqueToken);
168171
$stmt->execute();
169172

170173
// 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
@@ -180,11 +183,11 @@ public function putOffExpiration(Key $key, $ttl)
180183
*/
181184
public function delete(Key $key)
182185
{
183-
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token";
186+
$sql = "DELETE FROM $this->table WHERE $this->idCol = ? AND $this->tokenCol = ?";
184187
$stmt = $this->getConnection()->prepare($sql);
185188

186-
$stmt->bindValue(':id', $this->getHashedKey($key));
187-
$stmt->bindValue(':token', $this->getUniqueToken($key));
189+
$stmt->bindValue(1, $this->getHashedKey($key));
190+
$stmt->bindValue(2, $this->getUniqueToken($key));
188191
$stmt->execute();
189192
}
190193

@@ -193,11 +196,11 @@ public function delete(Key $key)
193196
*/
194197
public function exists(Key $key)
195198
{
196-
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token AND $this->expirationCol > {$this->getCurrentTimestampStatement()}";
199+
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = ? AND $this->tokenCol = ? AND $this->expirationCol > {$this->getCurrentTimestampStatement()}";
197200
$stmt = $this->getConnection()->prepare($sql);
198201

199-
$stmt->bindValue(':id', $this->getHashedKey($key));
200-
$stmt->bindValue(':token', $this->getUniqueToken($key));
202+
$stmt->bindValue(1, $this->getHashedKey($key));
203+
$stmt->bindValue(2, $this->getUniqueToken($key));
201204
$stmt->execute();
202205

203206
return (bool) $stmt->fetchColumn();

0 commit comments

Comments
 (0)