PHP Script to Display PHP Version and MySQL version of your website


There are times when you need to know the PHP version as well as the MySQL version used by your website. This is particularly important when you need to update the PHP version to the latest version as well as the MySQL server version installed.


Identifying PHP version seems to be pretty straightforward using phpinfo() functions however, if you need a PHP script that will right away display the PHP version as well as the MySQL version, you might be needing to use the script below:

<?php
//connect to database
$username = "Your MySQL username";
$password = "Your MySQL password";
$hostname = "Your MySQL hostname";
$database = "Your MySQL database name";
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($database,$dbhandle)
  or die("Could not select $database");
//display mysql version
$t=mysql_query("select version() as ve");
echo mysql_error();
$r=mysql_fetch_object($t);
echo 'MySQL version:'.$r->ve;
echo '<br />';
echo 'PHP version:'.PHP_VERSION;
?>

To implement the above script, fill it up with your own MySQL database connection parameters, save it as phpmysqlversion.php and then upload it to the root directory of your website. To view the results in the browser, you should enter it as: http://www.thisisanexamplewebsite.com/phpmysqlversion.php

This is particularly very useful if you are using WordPress. It is because they are announcing that they will not be any more supporting PHP 4 and MySQL 4 in the coming versions of WordPress (read more details here: http://wordpress.org/news/2010/07/eol-for-php4-and-mysql4/).

To prevent any problems, it is best to update your PHP and MySQL versions before it can introduce some incompatibility problems with your existing applications. So how you are going to update PHP version? The best way is to log in to your hosting control panel and then there are options there that will allow you to switch from PHP 4 to PHP 5. Most hosting companies are now supporting the latest PHP version which is PHP 5.

For updating MySQL server version to use the latest version, different hosting companies use different approach. For example, if you are using Godaddy hosting, you will need to backup your database first then create a new database using MySQL Version5. Once the database has been successfully created, you can restore the backup (from the old database) to your newly created database using latest MySQL version.

Finally, you can update the MySQL connection parameters (hostname, username, password). That’s it.



Related posts: