Skip to content

Commit c4f0519

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 590b732 commit c4f0519

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

doc/02-Installation.md.d/From-Source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Make sure you use `notifications` as the module name. The following requirements
1313
or [PostgreSQL](https://www.php.net/manual/en/ref.pdo-pgsql.php) PDO PHP libraries
1414
- [Icinga Notifications](https://github.com/Icinga/icinga-notifications)
1515
- [Icinga Web](https://github.com/Icinga/icingaweb2) (≥2.12)
16-
- [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.18)
16+
- [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.19)
1717
- [Icinga PHP Thirdparty](https://github.com/Icinga/icinga-php-thirdparty) (≥0.14)
1818

1919
<!-- {% include "02-Installation.md" %} -->

library/Notifications/Common/Database.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ipl\Sql\QueryBuilder;
1919
use ipl\Sql\Select;
2020
use ipl\Sql\Update;
21+
use Pdo\Mysql;
2122
use PDO;
2223

2324
final class Database
@@ -79,15 +80,7 @@ private static function getConnection(): Connection
7980

8081
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
8182
if ($config->db === 'mysql') {
82-
// As of PHP 8.5, driver-specific constants of the PDO class are deprecated,
83-
// but the replacement constants are only available since PHP 8.4.
84-
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
85-
$mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND;
86-
} else {
87-
$mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND;
88-
}
89-
90-
$config->options[$mysqlAttrInitCommand] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
83+
$config->options[Mysql::ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
9184
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
9285
}
9386

0 commit comments

Comments
 (0)