Use MySQL's VERSION() function when you need the server version from SQL. You can also inspect version-related system variables with SHOW VARIABLES.
SELECT VERSION() AS server_version;
SELECT VERSION();
The returned string identifies the running database server version. Version details matter when you are checking whether a feature or syntax is supported.
SHOW VARIABLES LIKE 'version%';
This can return several version-related system variables, not only the main server version.
This example assumes that config.php creates a PDO connection in $dbo.
<?php
require 'config.php';
$stmt = $dbo->query('SELECT VERSION() AS server_version');
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo 'MySQL version: ' . $row['server_version'];
?>
The PHP sample is static learner-facing HTML, so the variables above are displayed literally and are not interpolated by the host page.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| tommi | 16-03-2009 |
| thanks, it works... | |