@@ -34,6 +34,7 @@ trait PdoTrait
34
34
private $ username = '' ;
35
35
private $ password = '' ;
36
36
private $ connectionOptions = array ();
37
+ private $ namespace ;
37
38
38
39
private function init ($ connOrDsn , $ namespace , $ defaultLifetime , array $ options )
39
40
{
@@ -63,6 +64,7 @@ private function init($connOrDsn, $namespace, $defaultLifetime, array $options)
63
64
$ this ->username = isset ($ options ['db_username ' ]) ? $ options ['db_username ' ] : $ this ->username ;
64
65
$ this ->password = isset ($ options ['db_password ' ]) ? $ options ['db_password ' ] : $ this ->password ;
65
66
$ this ->connectionOptions = isset ($ options ['db_connection_options ' ]) ? $ options ['db_connection_options ' ] : $ this ->connectionOptions ;
67
+ $ this ->namespace = $ namespace ;
66
68
67
69
parent ::__construct ($ namespace , $ defaultLifetime );
68
70
}
@@ -142,10 +144,20 @@ public function createTable()
142
144
*/
143
145
public function prune ()
144
146
{
145
- $ deletes = $ this ->getConnection ()->prepare ("DELETE FROM $ this ->table WHERE $ this ->lifetimeCol + $ this ->timeCol <= :time " );
146
- $ deletes ->bindValue (':time ' , time (), \Pdo::PARAM_INT );
147
+ $ deleteSql = "DELETE FROM $ this ->table WHERE $ this ->lifetimeCol + $ this ->timeCol <= :time " ;
147
148
148
- return $ deletes ->execute ();
149
+ if ($ this ->namespace ) {
150
+ $ deleteSql .= " AND $ this ->idCol LIKE :namespace " ;
151
+ }
152
+
153
+ $ delete = $ this ->getConnection ()->prepare ($ deleteSql );
154
+ $ delete ->bindValue (':time ' , time (), \PDO ::PARAM_INT );
155
+
156
+ if ($ this ->namespace ) {
157
+ $ delete ->bindValue (':namespace ' , sprintf ('%s%% ' , $ this ->namespace ), \PDO ::PARAM_STR );
158
+ }
159
+
160
+ return $ delete ->execute ();
149
161
}
150
162
151
163
/**
0 commit comments