How to determine if a linked database is associated with MariaDB or MySQL?

My PHP application has requirements, including "MySQL 5.7+ or MariaDB 10.2+". How can I determine which of these alternatives is satisfied?

I know how to compare version numbers and also get the version number from the database, but I don’t know how to determine which database.

I tried

select version() 

This returns only the version number and server OS information, but not the database type.

-1
source share
3 answers
 $info = $pdo->query("SHOW VARIABLES like '%version%'")->fetchAll(PDO::FETCH_KEY_PAIR); $server_vendor = strtok($info['version_comment']," "); $server_version = $info['version']; 
0
source

Check out VARIABLES for aria_block_size . Its existence almost certainly implies some version of MariaDB, not MySQL, as well as Percona. (At least in the near future.)

Initial version :

  • "5.7" and "8.0" Suppose MySQL or Percona; it will not mean MariaDB.
  • "10.2" implies MariaDB; MySQL and Percona are unlikely to be at "10" for a long time.

What function do you need? There is a possibility that Percona will modify something from MariaDB 10.2 before it comes from MySQL.

Even when version is 5.1.53-rel11.7-log or 5.5.35-0ubuntu0.12.04.2-log , the first part gives you an important part of the MySQL / MariaDB / Percona version.

Percona versions look like this: 5.5.31-30.3-log , 5.6.30-76.3-56-log , 5.6.19-67.0-log - Pay attention to the additional 2 or 3 numbers after the initial 3.

MariaDB always starts with NNN-MariaDB

Oracle MySQL starts with NNN , but can continue with -enterprise (paid version), -community (free version), -0ubuntu0 (ported to Ubuntu), -Debian , etc.

MariaDB: 5.1, 5.2, 5.3, 5.4, 5.5, 10.0, 10.1, 10.2
Oracle and Percona: 5.1, 5.5, 5.6, 5.7, 8.0

Cycle 8.0 is just beginning. This means that 5.6 will close soon, and 5.7 has some kind of life left, but it will not have much new.

An explanation of what is the "main" release.
For MySQL (and Percona) they are "core" and they are not sequential ': 5.1, 5.5, 5.6, 5.7, 8.0.
For MariaDB: 5.1, 5.2, 5.3, 5.4, 5.5, 10.0, 10.1, 10.2.

0
source

if you are trying to do this from within a php application that you can (which version of php?) for PHP 7 uses mysqli_get_server_info; or <php 7, use mysql_get_Server_info

  <?php $link = mysqli_connect("localhost", "my_user", "my_password"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* print server version */ printf("Server version: %s\n", mysqli_get_server_info($link)); /* close connection */ mysqli_close($link); ?> 

will return

Server Version: 5.5.5-10.1.23- MariaDB -9 + deb9u1

php 7 http://php.net/manual/en/mysqli.get-server-info.php php 5 and < http://php.net/manual/en/function.mysql-get-server-info.php

0
source

All Articles