From 9adb6af958aad5b12d4eea61dbeb68af501ff710 Mon Sep 17 00:00:00 2001 From: 77web Date: Sun, 20 Sep 2026 15:06:24 +0900 Subject: [PATCH] applied fixes in upstream https://github.com/kamilwylegala/cakephp2-php8/pull/86: Fixing deprecation in PHP 8.5 PDO::MYSQL_ATTR_* constants are deprecated in PHP 8.5 in favor of the Pdo\Mysql class (available since PHP 8.1). Use the new constants when available, falling back to the deprecated ones on older PHP. The other two commits in PR #86 were intentionally not applied: - "Removed ancient code sniffer." drops cakephp/cakephp-codesniffer from composer.json, but this fork deliberately keeps it with documented advisory exceptions (CVE-2026-67434, PKSA-6vdd-n4sx-knhy). - "Skip DNS resolution failure." patches a DNS-dependent HttpSocketTest that this fork already replaced with a local TLS fixture server (c9c3b9ac9, 8ebbcbdc5), so the fix no longer applies. Co-Authored-By: Claude Sonnet 5 --- lib/Cake/Model/Datasource/Database/Mysql.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 7bc04663c0..40b8062a45 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -163,14 +163,23 @@ public function connect() { $config = $this->config; $this->connected = false; + // PDO::MYSQL_ATTR_* constants are deprecated in PHP 8.5; Pdo\Mysql class is available since PHP 8.1 + if (class_exists('Pdo\Mysql')) { + $mysqlAttrUseBufferedQuery = Pdo\Mysql::ATTR_USE_BUFFERED_QUERY; + $mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND; + } else { + $mysqlAttrUseBufferedQuery = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY; + $mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND; + } + $flags = $config['flags'] + array( PDO::ATTR_PERSISTENT => $config['persistent'], - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, + $mysqlAttrUseBufferedQuery => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); if (!empty($config['encoding'])) { - $flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding']; + $flags[$mysqlAttrInitCommand] = 'SET NAMES ' . $config['encoding']; } if (!empty($config['ssl_key']) && !empty($config['ssl_cert'])) { $flags[PDO::MYSQL_ATTR_SSL_KEY] = $config['ssl_key'];