jump to navigation

Finding Mysql’s verion with PHP November 21, 2011

Posted by Tournas Dimitrios in PHP.
trackback

There are different ways to show Mysql’s version number  :

  • via the terminal -> mysql  -v ,
  •  PHPMyadmin , on the right side panel when logging-in (some providers disable this information )  
  • Running a ” VERSION()” SQL statement with PHP

And what about phpinfo() , you may ask .  It shows the ” Client API version” not your Mysql version .

You may ofter notice that phpinfo() will be showing your MySQL Client API version as 5.0.51a which may not be your actual MySQL version(Usually it will be higher than this). The reason behind this is phpinfo() displays PHP client-side information. PHP is built against the old libmysqlclient15off (5.0.51a) to avoid Apache-related issues and segfaults. This has nothing to deal with the MySQL server version. Also, 5.0.51a-linked clients interacts with higher version MySQL databases (like 5.1.41) without any issue. So, just ignore this difference . Source ….

Let’s create a PHP-script to show Mysql’s version  :

<?php
//Using Mysqli's OOP
$mysqli = new mysqli("localhost", "root", "");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s", mysqli_connect_error());
exit();
}

/* print server version */
printf("Server version: %s", $mysqli->server_info);

/* close connection */
$mysqli->close();


#############################
//Using Mysqli's Procedural #
#############################
$link = mysqli_connect("localhost", "root", "");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s", mysqli_connect_error());
exit();
}

/* print server version */
printf("Server version: %s
", mysqli_get_server_info($link));

/* close connection */
mysqli_close($link);

#########################
//Using Mysql #
#########################
$db = mysql_connect("localhost", "root", "") or die('Cannot connect to database');
$result = mysql_query('SELECT VERSION()') or die(mysql_error());
printf("Server version: %s", mysql_result($result, 0));
mysql_close();






?>
Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s