From 1af1e6a22805f1fedb461e9d4315b6f0edc689fc Mon Sep 17 00:00:00 2001 From: Bastian Lederer Date: Tue, 10 Mar 2026 09:50:32 +0100 Subject: [PATCH] Use `Pdo\Mysql` driver-specific constants Replace deprecated `PDO::MYSQL_*` constant usage with the driver-specific `Pdo\Mysql::ATTR_*` constants introduced in PHP 8.4. This prepares the code for PHP 8.5, where accessing MySQL driver constants through the generic `PDO` class is deprecated. This change requires a compatibility shim on older PHP versions to provide `Pdo\Mysql` for runtimes that do not expose the driver-specific class yet. The shim is provided in `ipl-sql`. As a consequence, the required version of the Icinga PHP library has been raised. --- doc/02-Installation.md | 2 +- library/Reporting/Database.php | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/doc/02-Installation.md b/doc/02-Installation.md index 8b04fff5..c4bc7da1 100644 --- a/doc/02-Installation.md +++ b/doc/02-Installation.md @@ -10,7 +10,7 @@ Make sure you use `reporting` as the module name. The following requirements mus * MySQL or PostgreSQL PDO PHP libraries * The following PHP modules must be installed: `mbstring` * [Icinga Web](https://github.com/Icinga/icingaweb2) (≥2.9) -* [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.13.0) +* [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.19.0) * [Icinga PHP Thirdparty](https://github.com/Icinga/icinga-php-thirdparty) (≥0.12.0) ## Setting up the Database diff --git a/library/Reporting/Database.php b/library/Reporting/Database.php index fdd3df98..a96af16d 100644 --- a/library/Reporting/Database.php +++ b/library/Reporting/Database.php @@ -8,6 +8,7 @@ use Icinga\Application\Config; use Icinga\Data\ResourceFactory; use ipl\Sql; +use Pdo\Mysql; use PDO; use stdClass; @@ -44,14 +45,7 @@ private static function getDb(): RetryConnection $config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]; if ($config->db === 'mysql') { - // In PHP 8.5+, driver-specific constants of the PDO class are deprecated, - // but the replacements are only available since php 8.4 - if (version_compare(PHP_VERSION, '8.4.0', '<')) { - $mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND; - } else { - $mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND; - } - $config->options[$mysqlAttrInitCommand] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES" + $config->options[Mysql::ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES" . ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"; }