Skip to content

Use PHP_VERSION_ID to select Pdo\Mysql constants in Mysql::connect() - #33

Merged
basi merged 2 commits into
basi:mainfrom
77web:feat/improve-version-detection-mysql
Sep 30, 2026
Merged

basi merged 2 commits into
basi:mainfrom
77web:feat/improve-version-detection-mysql

Conversation

@77web

@77web 77web commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #27, addressing #27 (comment)

Changes

  • Pdo\Mysql was added in PHP 8.4.0, not 8.1 (docs). Fix the comment.
  • Replace class_exists('Pdo\Mysql') with PHP_VERSION_ID >= 80400:
    • avoids running the autoloader chain on every connect() on PHP < 8.4
    • a userland Pdo\Mysql class can no longer be misdetected
    • same approach as CakePHP 4.x/5.x
  • Route the SSL options (ssl_key / ssl_cert / ssl_ca) through Pdo\Mysql::ATTR_SSL_* too, so they no longer trigger PHP 8.5 deprecations.

Verification

  • php -l passes on PHP 8.1 / 8.4 / 8.5 (official Docker images)
  • With pdo_mysql on PHP 8.4 / 8.5, all the Pdo\Mysql::ATTR_* constants used here resolve without deprecation warnings

🤖 Generated with Claude Code

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>
@77web
77web requested a review from basi September 29, 2026 12:02

@basi basi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_* and Pdo\Mysql::ATTR_* from the same C values (on 8.5 the former as deprecated aliases), so the flag keys passed to new PDO() are unchanged. The ssl_* → 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.4 branch.
  • All five constants are resolved at the top of connect(). The 8.0 MySQL job runs the PDO::MYSQL_ATTR_* branch and the 8.4 job runs the Pdo\Mysql branch, even though the CI config sets neither encoding nor ssl_*.
  • Without pdo_mysql, DboSource::__construct() throws MissingConnectionException via enabled() before connect() runs, so referencing Pdo\Mysql directly 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-DD heading? For example:
    - 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.
    I'll approve once it's in.

Optional

  • Upstream master still has the class_exists() check, the "8.1" comment and PDO::MYSQL_ATTR_SSL_*, so this change could be sent upstream too.

@basi basi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@77web

77web commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

@basi Thank you for your review. I added a changelog in README.md.

@77web
77web requested a review from basi September 30, 2026 06:12

@basi basi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@basi
basi merged commit 3de4778 into basi:main Sep 30, 2026
4 checks passed
@77web
77web deleted the feat/improve-version-detection-mysql branch September 30, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants