Skip to content

Commit 6bc73b0

Browse files
committed
fix(PDO): Switch away from deprecated PDO parts
Signed-off-by: Joas Schilling <[email protected]>
1 parent 121973d commit 6bc73b0

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/private/DB/ConnectionFactory.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,23 @@ public function getDefaultConnectionParams($type) {
8888
throw new \InvalidArgumentException("Unsupported type: $type");
8989
}
9090
$result = $this->defaultConnectionParams[$normalizedType];
91-
// \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL
92-
// driver is missing. In this case, we won't be able to connect anyway.
93-
if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) {
94-
$result['driverOptions'] = [
95-
\PDO::MYSQL_ATTR_FOUND_ROWS => true,
96-
];
91+
/**
92+
* {@see \PDO::MYSQL_ATTR_FOUND_ROWS} may not be defined, e.g. when the MySQL
93+
* driver is missing. In this case, we won't be able to connect anyway.
94+
* In PHP 8.5 it's deprecated and {@see \Pdo\Mysql::ATTR_FOUND_ROWS} should be used,
95+
* but that is only available since PHP 8.4
96+
*/
97+
if ($normalizedType === 'mysql') {
98+
if (PHP_VERSION_ID >= 80500 && class_exists(\Pdo\Mysql::class)) {
99+
/** @psalm-suppress UndefinedClass */
100+
$result['driverOptions'] = [
101+
\Pdo\Mysql::ATTR_FOUND_ROWS => true,
102+
];
103+
} elseif (PHP_VERSION_ID < 80500 && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) {
104+
$result['driverOptions'] = [
105+
\PDO::MYSQL_ATTR_FOUND_ROWS => true,
106+
];
107+
}
97108
}
98109
return $result;
99110
}

lib/private/DB/SQLiteSessionInit.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public function postConnect(ConnectionEventArgs $args) {
4444
/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
4545
$connection = $args->getConnection()->getWrappedConnection();
4646
$pdo = $connection->getWrappedConnection();
47-
$pdo->sqliteCreateFunction('md5', 'md5', 1);
47+
if (PHP_VERSION_ID >= 80500 && method_exists($pdo, 'createFunction')) {
48+
$pdo->createFunction('md5', 'md5', 1);
49+
} else {
50+
$pdo->sqliteCreateFunction('md5', 'md5', 1);
51+
}
4852
}
4953

5054
public function getSubscribedEvents() {

0 commit comments

Comments
 (0)