How to know Mysql Version Using PHP
Thursday, April 8, 2010 2:11How to know Mysql Version Using PHP ?.
We can know the mysql version in the phpinfo. But if we want to display the mysql version in any web page dynamically, how we are you going to deal with that ?.
A little bit logic and a liitle bit manipulation on the phpinfo information we can achieve that.
Create a file like this and name it as phpinfo.php
<?php phpinfo(); ?>
Create another file mysql_version.php with the following code
<?php
$file = @file_get_contents("http://DOMAINNAME/phpinfo.php");
$start = explode("<h2><a name=\"module_mysql\">mysql</a></h2>",$file,1000);
if(count($start) < 2){
echo "MySQL is not on this server.";
}else{
$again = explode("<tr><td class=\"e\">Client API version </td><td class=\"v\">",$start[1],1000);
$last_time = explode(" </td></tr>",$again[1],1000);
echo "MySQL Version: <b>".$last_time[0]."</b>";
}
?>
replace “DOMAINNAME” with your domain name.
This is one of the solution.
You can also know the mysql version if you are using a linux server and you have the permission to execute the shell commands, the following code will work.
<?php
function find_SQL_Version() {
$output = shell_exec('mysql -V');
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
return $version[0];
}
echo 'Your SQL version is ' . find_SQL_Version();
?>
If any one know other than these methods please feel free to share with us.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.