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/Adapter/Mysql.php b/src/Adapter/Mysql.php index 7146579..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 { @@ -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[PdoMysql::ATTR_SSL_KEY] = $config->sslKey; } if (! empty($config->sslCert)) { - $options[constant($mysqlConstantPrefix . 'SSL_CERT')] = $config->sslCert; + $options[PdoMysql::ATTR_SSL_CERT] = $config->sslCert; } if (! empty($config->sslCa)) { - $options[constant($mysqlConstantPrefix . 'SSL_CA')] = $config->sslCa; + $options[PdoMysql::ATTR_SSL_CA] = $config->sslCa; } if (! empty($config->sslCapath)) { - $options[constant($mysqlConstantPrefix . 'SSL_CAPATH')] = $config->sslCapath; + $options[PdoMysql::ATTR_SSL_CAPATH] = $config->sslCapath; } if (! empty($config->sslCipher)) { - $options[constant($mysqlConstantPrefix . 'SSL_CIPHER')] = $config->sslCipher; + $options[PdoMysql::ATTR_SSL_CIPHER] = $config->sslCipher; } if ( - defined($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT') + defined(PdoMysql::class . '::ATTR_SSL_VERIFY_SERVER_CERT') && ! empty($config->sslDoNotVerifyServerCert) ) { - $options[constant($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT')] = false; + $options[PdoMysql::ATTR_SSL_VERIFY_SERVER_CERT] = false; } } 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 @@ +