Skip to content
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

Query database to retrieve mysql-version to support mariadb and other… #19

Closed
wants to merge 1 commit into from

Conversation

benediktblank
Copy link

… distros with non-standard ports, attributes etc.

Description

We had an issue on Azure, that in certain conditions the version retrieved from PDO::ATTR_SERVER_VERSION was completely wrong, not even a mariadb version.
That PR would change the version check here to a query directly on the database to get the version.
If that fails, it would fallback to PDO::ATTR_SERVER_VERSIO

Related issues

… distros with non-standard ports, attributes etc.
@angrybrad
Copy link
Member

This would get you past the server check logic, but there are other places where Craft (and the underlying framework Yii), use PDO::ATTR_SERVER_VERSION checks to determine what SQL to generate and/or logic to run.

You can search for Craft::$app->getDb()->getSchema()->getServerVersion() to see a list.

Seems like Azure has a workaround for this... if you use ports 3308 or 3309, it'll end up reporting the correct MySQL version.

https://docs.microsoft.com/en-us/azure/mysql/single-server/concepts-connect-to-a-gateway-node

@angrybrad angrybrad closed this Sep 6, 2022
@benediktblank
Copy link
Author

benediktblank commented Sep 7, 2022

This would get you past the server check logic, but there are other places where Craft (and the underlying framework Yii), use PDO::ATTR_SERVER_VERSION checks to determine what SQL to generate and/or logic to run.

You can search for Craft::$app->getDb()->getSchema()->getServerVersion() to see a list.

Seems like Azure has a workaround for this... if you use ports 3308 or 3309, it'll end up reporting the correct MySQL version.

https://docs.microsoft.com/en-us/azure/mysql/single-server/concepts-connect-to-a-gateway-node

I know this work around, but it doesn't work for MariaDB with disabled SSL.
When you run a MariaDB service and disable SSL connection it always returns a MySQL version, on every port:

bash-5.1$ php sqltest.php
Port: 3306
5.6.47.0
bash-5.1$ php sqltest.php
Port: 3308
5.7.29.0
bash-5.1$ php sqltest.php
Port: 3309
8.0.15.0

I've searched for "Craft::$app->getDb()->getSchema()->getServerVersion()" as suggested and it only came up with one result in cms/application/vendor/craftcms/cms/src/db/mysql/Schema.php inside the getDefaultBackupCommand function.

Are there more?

@angrybrad
Copy link
Member

When you run a MariaDB service and disable SSL connection it always returns a MySQL version, on every port:

Ewww...

getSchema()->getServerVersion() would probably be a better search - I'm counting 10 instances across Craft and Yii on a fresh installation.

But even then, there's nothing stopping a plugin or custom module from doing PDO::ATTR_SERVER_VERSION and getting improper results. 🤔

@benediktblank
Copy link
Author

When you run a MariaDB service and disable SSL connection it always returns a MySQL version, on every port:

Ewww...

Yeah, it's really bad.

getSchema()->getServerVersion() would probably be a better search - I'm counting 10 instances across Craft and Yii on a fresh installation.

But even then, there's nothing stopping a plugin or custom module from doing PDO::ATTR_SERVER_VERSION and getting improper results. 🤔

Alright. We've talked with Microsoft now directly and there apparently is a better server structure that should give us the correct version. It seems the others are kind of "legacy".

@angrybrad
Copy link
Member

angrybrad commented Sep 8, 2022

Interesting - do you happen to have a public link to what Microsoft said so we can point people that run into this in the future?

@benediktblank
Copy link
Author

Interesting - do you happen to have a public link to what Microsoft said so we can point people that run into this in the future?

It's called "Azure Database for MySQL Flexible Server". MariaDB is currently not available for these so we will switch to MySQL now. But it's apparently more modern server structure compared to the other services.

@angrybrad
Copy link
Member

@benediktblank thanks for that!

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