From 074d118a311060349a776402a252ce1cbec49b18 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 9 Mar 2026 15:43:00 +0100 Subject: [PATCH 1/3] Add forward compatibility for `PDO` MySQL driver constants PHP 8.4 introduced driver-specific `PDO` MySQL constants on `Pdo\Mysql`, and PHP 8.5 deprecates accessing those constants through the generic `PDO` class. Add a forward-compatibility shim that provides `Pdo\Mysql::ATTR_*` on older PHP versions when pdo_mysql is available. The shim mirrors the mysqlnd and non-mysqlnd differences in available constants so existing code can switch to the driver-specific API without dropping support for older runtimes. --- composer.json | 3 ++ src/pdo-driver-consts-forward-compat.php | 62 ++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/pdo-driver-consts-forward-compat.php diff --git a/composer.json b/composer.json index 882e054..2dd665d 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,9 @@ "ipl/stdlib": "dev-main" }, "autoload": { + "files": [ + "src/pdo-driver-consts-forward-compat.php" + ], "psr-4": { "ipl\\Sql\\": "src" } diff --git a/src/pdo-driver-consts-forward-compat.php b/src/pdo-driver-consts-forward-compat.php new file mode 100644 index 0000000..3ba6ae8 --- /dev/null +++ b/src/pdo-driver-consts-forward-compat.php @@ -0,0 +1,62 @@ + Date: Mon, 9 Mar 2026 15:45:06 +0100 Subject: [PATCH 2/3] Revert "Use PDO constants adequate for the running PHP version" This reverts commit 8520935b21bda8bf28437ea9c6c475781b7ac272. The shim introduced in 074d118 allows us to use `PDO` MySQL driver-specific constants, which will be introduced in a subsequent commit. --- src/Adapter/Mysql.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Adapter/Mysql.php b/src/Adapter/Mysql.php index 7146579..2421cae 100644 --- a/src/Adapter/Mysql.php +++ b/src/Adapter/Mysql.php @@ -22,40 +22,33 @@ public function setClientTimezone(Connection $db) public function getOptions(Config $config) { $options = parent::getOptions($config); - // 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', '<')) { - $mysqlConstantPrefix = 'PDO::MYSQL_ATTR_'; - } else { - $mysqlConstantPrefix = 'Pdo\Mysql::ATTR_'; - } if (! empty($config->useSsl)) { if (! empty($config->sslKey)) { - $options[constant($mysqlConstantPrefix . 'SSL_KEY')] = $config->sslKey; + $options[PDO::MYSQL_ATTR_SSL_KEY] = $config->sslKey; } if (! empty($config->sslCert)) { - $options[constant($mysqlConstantPrefix . 'SSL_CERT')] = $config->sslCert; + $options[PDO::MYSQL_ATTR_SSL_CERT] = $config->sslCert; } if (! empty($config->sslCa)) { - $options[constant($mysqlConstantPrefix . 'SSL_CA')] = $config->sslCa; + $options[PDO::MYSQL_ATTR_SSL_CA] = $config->sslCa; } if (! empty($config->sslCapath)) { - $options[constant($mysqlConstantPrefix . 'SSL_CAPATH')] = $config->sslCapath; + $options[PDO::MYSQL_ATTR_SSL_CAPATH] = $config->sslCapath; } if (! empty($config->sslCipher)) { - $options[constant($mysqlConstantPrefix . 'SSL_CIPHER')] = $config->sslCipher; + $options[PDO::MYSQL_ATTR_SSL_CIPHER] = $config->sslCipher; } if ( - defined($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT') + defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') && ! empty($config->sslDoNotVerifyServerCert) ) { - $options[constant($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT')] = false; + $options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false; } } From 88165f637e80adefdb18ea9af1b430a52f4400a4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 9 Mar 2026 16:01:33 +0100 Subject: [PATCH 3/3] 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 the compatibility shim (074d118) on older PHP versions to provide `Pdo\Mysql` for runtimes that do not expose the driver-specific class yet. --- src/Adapter/Mysql.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Adapter/Mysql.php b/src/Adapter/Mysql.php index 2421cae..52c8c0c 100644 --- a/src/Adapter/Mysql.php +++ b/src/Adapter/Mysql.php @@ -4,7 +4,7 @@ use ipl\Sql\Config; use ipl\Sql\Connection; -use PDO; +use Pdo\Mysql as PdoMysql; class Mysql extends BaseAdapter { @@ -25,30 +25,30 @@ public function getOptions(Config $config) if (! empty($config->useSsl)) { if (! empty($config->sslKey)) { - $options[PDO::MYSQL_ATTR_SSL_KEY] = $config->sslKey; + $options[PdoMysql::ATTR_SSL_KEY] = $config->sslKey; } if (! empty($config->sslCert)) { - $options[PDO::MYSQL_ATTR_SSL_CERT] = $config->sslCert; + $options[PdoMysql::ATTR_SSL_CERT] = $config->sslCert; } if (! empty($config->sslCa)) { - $options[PDO::MYSQL_ATTR_SSL_CA] = $config->sslCa; + $options[PdoMysql::ATTR_SSL_CA] = $config->sslCa; } if (! empty($config->sslCapath)) { - $options[PDO::MYSQL_ATTR_SSL_CAPATH] = $config->sslCapath; + $options[PdoMysql::ATTR_SSL_CAPATH] = $config->sslCapath; } if (! empty($config->sslCipher)) { - $options[PDO::MYSQL_ATTR_SSL_CIPHER] = $config->sslCipher; + $options[PdoMysql::ATTR_SSL_CIPHER] = $config->sslCipher; } if ( - defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') + defined(PdoMysql::class . '::ATTR_SSL_VERIFY_SERVER_CERT') && ! empty($config->sslDoNotVerifyServerCert) ) { - $options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false; + $options[PdoMysql::ATTR_SSL_VERIFY_SERVER_CERT] = false; } }