Skip to content

Do not require full MySQL version for static DSN versioning #6911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
speller opened this issue Apr 16, 2025 · 1 comment
Open

Do not require full MySQL version for static DSN versioning #6911

speller opened this issue Apr 16, 2025 · 1 comment

Comments

@speller
Copy link

speller commented Apr 16, 2025

Proposal

Q A
Version 4.2.3

Summary

If I configure the MySQL version to 8.4 statically to avoid dynamic detection with an extra DB query, the driver class is selected incorrectly. DBAL selects the MySQL80Platform instead of MySQL84Platform.

Current behavior

DBAL selects the MySQL80Platform instead of MySQL84Platform.

Expected behavior

DBAL selects the MySQL84Platform.

How to reproduce

Configure DSN with the serverVersion=8.4 parameter.

Context:

I want to configure my project to work with any 8.4 db version. I don't want to track a specific version that the project is running against. It may run against different patch versions on different deployments (local, staging, prod). So I expect DBAL understand the 8.4 static version configuration. The simplest workaround is to specify a fake full version as mentioned in the documentation:

Please specify the full server version as the database server would report it. This is especially important for MySQL and MariaDB where the full version string is taken into account when determining the platform.

But this is not true. The patch part of the version in fact, does NOT affect the driver selection. I can pass ANY patch version, and only the minor version will be taken into account:

        if (version_compare($version, '8.4.0', '>=')) {
            return new MySQL84Platform();
        }

        if (version_compare($version, '8.0.0', '>=')) {
            return new MySQL80Platform();
        }

I.e. if I pass version number 8.4.0 or 8.4.9999999 - the result will be the same, the MySQL84Platform class will be selected. So why should users pass the full version instead of simply major and minor? Is the requirement to pass the full version something legacy?

@andrew-demb
Copy link
Contributor

Changing 8.4.0 to 8.4 for version_compare call seems enough to simplify the configuration.

<?php

$version = '8.4';

echo $version, PHP_EOL;
var_dump(version_compare($version, '8.4.0', '>='));
var_dump(version_compare($version, '8.4', '>='));

echo '--------', PHP_EOL;

$version = '8.4.0';

echo $version, PHP_EOL;
var_dump(version_compare($version, '8.4.0', '>='));
var_dump(version_compare($version, '8.4', '>='));
8.4
bool(false)
bool(true)
--------
8.4.0
bool(true)
bool(true)

https://3v4l.org/buhVp

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

No branches or pull requests

2 participants