Use PHP_VERSION_ID to select Pdo\Mysql constants in Mysql::connect() - #33
Conversation
Pdo\Mysql was added in PHP 8.4, not 8.1. Switch from class_exists() to a PHP_VERSION_ID >= 80400 check so the autoloader chain is not triggered on every connect() and a userland Pdo\Mysql class cannot be misdetected (same approach as CakePHP 4.x/5.x). Also route the SSL attributes through Pdo\Mysql::ATTR_SSL_* to avoid PHP 8.5 deprecations. Follow-up to basi#27 (comment) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
basi
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. The code change looks correct and covers the code items from the #27 review: the SSL constants, the "8.1" comment and the PHP_VERSION_ID check.
Checked
- On PHP 8.4+, pdo_mysql registers
PDO::MYSQL_ATTR_*andPdo\Mysql::ATTR_*from the same C values (on 8.5 the former as deprecated aliases), so the flag keys passed tonew PDO()are unchanged. Thessl_*→ATTR_SSL_*mapping matches the old code. - After this change, the only code references to
PDO::MYSQL_ATTR_*left in the repository are in the< 8.4branch. - All five constants are resolved at the top of
connect(). The 8.0 MySQL job runs thePDO::MYSQL_ATTR_*branch and the 8.4 job runs thePdo\Mysqlbranch, even though the CI config sets neitherencodingnorssl_*. - Without pdo_mysql,
DboSource::__construct()throwsMissingConnectionExceptionviaenabled()beforeconnect()runs, so referencingPdo\Mysqldirectly adds no new failure mode.
Remaining from the #27 follow-up scope
- Should: the README Changelog entry is still missing. Could you add it to this PR under a new
### YYYY-MM-DDheading? For example:I'll approve once it's in.- Fix the PHP 8.5 `PDO::MYSQL_ATTR_*` deprecations in the MySQL datasource: on PHP >= 8.4, `Mysql::connect()` uses the `Pdo\Mysql::ATTR_*` constants, including the SSL ones (based on kamilwylegala/cakephp2-php8#86). Apps passing `PDO::MYSQL_ATTR_*` in the datasource `flags` option should switch to `Pdo\Mysql::ATTR_*` on PHP >= 8.4 as well.
Optional
- Upstream master still has the
class_exists()check, the "8.1" comment andPDO::MYSQL_ATTR_SSL_*, so this change could be sent upstream too.
basi
left a comment
There was a problem hiding this comment.
Reviewed commit 75f5331. No additional code defects found. The version guard and SSL attribute mappings are correct, and all five replacement constants preserve the existing option keys.
CI passes all four jobs. I also verified constant equivalence on PHP 8.4 and syntax on PHP 8.5; PHP 8.5 SSL connections were not exercised.
The README Changelog entry requested in the existing review remains outstanding.
|
@basi Thank you for your review. I added a changelog in README.md. |
basi
left a comment
There was a problem hiding this comment.
Thanks for adding the Changelog entry. Re-checked 25dc516: it only adds the ### 2026-09-30 section to README.md, with the wording suggested in the earlier review, and Mysql.php is unchanged from 75f5331. CI is green on all four jobs. Approving.
Follow-up to #27, addressing #27 (comment)
Changes
Pdo\Mysqlwas added in PHP 8.4.0, not 8.1 (docs). Fix the comment.class_exists('Pdo\Mysql')withPHP_VERSION_ID >= 80400:connect()on PHP < 8.4Pdo\Mysqlclass can no longer be misdetectedssl_key/ssl_cert/ssl_ca) throughPdo\Mysql::ATTR_SSL_*too, so they no longer trigger PHP 8.5 deprecations.Verification
php -lpasses on PHP 8.1 / 8.4 / 8.5 (official Docker images)Pdo\Mysql::ATTR_*constants used here resolve without deprecation warnings🤖 Generated with Claude Code