Skip to content

Commit c801c23

Browse files
Replace deprecated (since php8.5) PDO constant PDO::MYSQL_ATTR_INIT_COMMAND
ref https://www.php.net/manual/en/migration85.deprecated.php#migration85.deprecated.pdo
1 parent a4b4759 commit c801c23

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

library/Reporting/Database.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ private static function getDb(): RetryConnection
4343

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

0 commit comments

Comments
 (0)