Reputation: 446
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?
Upvotes: 20
Views: 30197
Reputation: 652
mysql_get_client_info() is deprecated. For PHP 7 and above you have to use:
echo mysqli_get_client_info();
Upvotes: 2
Reputation: 2082
Information output by phpinfo
should be accurate.
Just add the following to a file & visit it in the browser:
<?php phpinfo();
& find the mysql version under mysql >> Client API version
Upvotes: 3
Reputation: 53830
You'll need the user to enter their DB credentials, so you can connect to the MySQL server and run the following query to get the MySQL server version:
SHOW VARIABLES LIKE 'version'
Here's the output on my server:
Variable_name Value
----------------------------
version 5.1.53-log
Upvotes: 16
Reputation: 407
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);
Upvotes: 25