bug #25922 [HttpFoundation] Use the correct syntax for session gc based on Pdo driver (tanasecosminromeo)

This PR was submitted for the master branch but it was squashed and merged into the 2.7 branch instead (closes #25922).

Discussion
----------

[HttpFoundation] Use the correct syntax for session gc based on Pdo driver

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25665 #24456
| License       | MIT
| Doc PR        |

The initial fix for #24456 was wrong, since it only accounted for Postgres. @WhiteEagle88 correctly identified #25665 - but having time as SIGNED is ... off, since time shouldn't be negative. Using CAST to solve this issue surely has a performance penalty, so I believe the best approach is to have a switch based on the driver.

Commits
-------

826dfbd496 [HttpFoundation] Use the correct syntax for session gc based on Pdo driver
This commit is contained in:
Fabien Potencier 2018-01-29 09:51:56 +01:00
commit 5e3aa676eb

View File

@ -375,7 +375,11 @@ class PdoSessionHandler implements \SessionHandlerInterface
$this->gcCalled = false;
// delete the session records that have expired
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time - $this->timeCol";
if ('mysql' === $this->driver) {
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time";
} else {
$sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time - $this->timeCol";
}
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);