From 6bc73b0dab7b91630ade18c5adc2ad991b7f1e1d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Dec 2025 08:05:13 +0100 Subject: [PATCH] fix(PDO): Switch away from deprecated PDO parts Signed-off-by: Joas Schilling --- lib/private/DB/ConnectionFactory.php | 23 +++++++++++++++++------ lib/private/DB/SQLiteSessionInit.php | 6 +++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index 2429eeb142f..42112560311 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -88,12 +88,23 @@ class ConnectionFactory { throw new \InvalidArgumentException("Unsupported type: $type"); } $result = $this->defaultConnectionParams[$normalizedType]; - // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL - // driver is missing. In this case, we won't be able to connect anyway. - if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { - $result['driverOptions'] = [ - \PDO::MYSQL_ATTR_FOUND_ROWS => true, - ]; + /** + * {@see \PDO::MYSQL_ATTR_FOUND_ROWS} may not be defined, e.g. when the MySQL + * driver is missing. In this case, we won't be able to connect anyway. + * In PHP 8.5 it's deprecated and {@see \Pdo\Mysql::ATTR_FOUND_ROWS} should be used, + * but that is only available since PHP 8.4 + */ + if ($normalizedType === 'mysql') { + if (PHP_VERSION_ID >= 80500 && class_exists(\Pdo\Mysql::class)) { + /** @psalm-suppress UndefinedClass */ + $result['driverOptions'] = [ + \Pdo\Mysql::ATTR_FOUND_ROWS => true, + ]; + } elseif (PHP_VERSION_ID < 80500 && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { + $result['driverOptions'] = [ + \PDO::MYSQL_ATTR_FOUND_ROWS => true, + ]; + } } return $result; } diff --git a/lib/private/DB/SQLiteSessionInit.php b/lib/private/DB/SQLiteSessionInit.php index 5fe0cb3abf6..3e05b6e59a1 100644 --- a/lib/private/DB/SQLiteSessionInit.php +++ b/lib/private/DB/SQLiteSessionInit.php @@ -44,7 +44,11 @@ class SQLiteSessionInit implements EventSubscriber { /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */ $connection = $args->getConnection()->getWrappedConnection(); $pdo = $connection->getWrappedConnection(); - $pdo->sqliteCreateFunction('md5', 'md5', 1); + if (PHP_VERSION_ID >= 80500 && method_exists($pdo, 'createFunction')) { + $pdo->createFunction('md5', 'md5', 1); + } else { + $pdo->sqliteCreateFunction('md5', 'md5', 1); + } } public function getSubscribedEvents() {