fix(PDO): Switch away from deprecated PDO parts

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2025-12-18 08:05:13 +01:00
parent 121973d336
commit 6bc73b0dab
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 22 additions and 7 deletions

View file

@ -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;
}

View file

@ -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() {