31
31
* To ensure locks don't expire prematurely; the TTLs should be set with enough
32
32
* extra time to account for any clock drift between nodes.
33
33
*
34
+ * CAUTION: The queries in this class must not use named params
35
+ * because the mysqli driver does not support them.
36
+ *
34
37
* @author Jérémy Derussé <[email protected] >
35
38
*/
36
39
class PdoStore implements StoreInterface
@@ -116,11 +119,11 @@ public function save(Key $key)
116
119
{
117
120
$ key ->reduceLifetime ($ this ->initialTtl );
118
121
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 ) " ;
120
123
$ stmt = $ this ->getConnection ()->prepare ($ sql );
121
124
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 ));
124
127
125
128
try {
126
129
$ stmt ->execute ();
@@ -158,13 +161,13 @@ public function putOffExpiration(Key $key, $ttl)
158
161
159
162
$ key ->reduceLifetime ($ ttl );
160
163
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 ()}) " ;
162
165
$ stmt = $ this ->getConnection ()->prepare ($ sql );
163
166
164
167
$ 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 );
168
171
$ stmt ->execute ();
169
172
170
173
// 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)
180
183
*/
181
184
public function delete (Key $ key )
182
185
{
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 = ? " ;
184
187
$ stmt = $ this ->getConnection ()->prepare ($ sql );
185
188
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 ));
188
191
$ stmt ->execute ();
189
192
}
190
193
@@ -193,11 +196,11 @@ public function delete(Key $key)
193
196
*/
194
197
public function exists (Key $ key )
195
198
{
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 ()}" ;
197
200
$ stmt = $ this ->getConnection ()->prepare ($ sql );
198
201
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 ));
201
204
$ stmt ->execute ();
202
205
203
206
return (bool ) $ stmt ->fetchColumn ();
0 commit comments