Skip to content

Commit 11e34f5

Browse files
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.
1 parent 238a8fb commit 11e34f5

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

doc/02-Installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Make sure you use `reporting` as the module name. The following requirements mus
1010
* MySQL or PostgreSQL PDO PHP libraries
1111
* The following PHP modules must be installed: `mbstring`
1212
* [Icinga Web](https://github.com/Icinga/icingaweb2) (≥2.9)
13-
* [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.13.0)
13+
* [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.19.0)
1414
* [Icinga PHP Thirdparty](https://github.com/Icinga/icinga-php-thirdparty) (≥0.12.0)
1515

1616
## Setting up the Database

library/Reporting/Database.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Icinga\Application\Config;
99
use Icinga\Data\ResourceFactory;
1010
use ipl\Sql;
11+
use Pdo\Mysql;
1112
use PDO;
1213
use stdClass;
1314

@@ -44,14 +45,7 @@ private static function getDb(): RetryConnection
4445

4546
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
4647
if ($config->db === 'mysql') {
47-
// In PHP 8.5+, driver-specific constants of the PDO class are deprecated,
48-
// but the replacements are only available since php 8.4
49-
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
50-
$mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND;
51-
} else {
52-
$mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND;
53-
}
54-
$config->options[$mysqlAttrInitCommand] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
48+
$config->options[Mysql::ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
5549
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
5650
}
5751

0 commit comments

Comments
 (0)