Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get server MySQL version in PHP without connecting

Tags:

php

mysql

I need to echo the MySQL version in a PHP script (it's a server requirement check page for users before downloading the plugin) without having them connect to their database.

The upload this script to their server and open it in the browser. I could ask them to run php info but all I need is the Mysql version and it gets formatted in the script with the rest of the results.

How should i go about this?

like image 889
Chris81 Avatar asked May 02 '12 13:05

Chris81


1 Answers

If you have access to the command line mysql executable you can try this:

function getMySQLVersion() { 
  $output = shell_exec('mysql -V'); 
  preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
  return $version[0]; 
}

For the client version:

print mysql_get_client_info();

Without shell access to get the server version you must connect first:

$link = mysql_connect("localhost", "username", "password");
if (!$link) die('Could not connect: ' . mysql_error());
print "MySQL server version: " . mysql_get_server_info();
mysql_close($link);
like image 62
Tim Avatar answered Oct 26 '22 10:10

Tim