Get MySQL Version Information Through PHP

13th April 2008

There is little syntactical difference between MySQL 4 and MySQL 5, but sometimes finding that difference can pinpoint a bug. The mysql_get_server_info() function will tell you what version of MySQL you are using. You can call it with no parameters, in which case it picks the most recently created MySQL resource, or with the resource handle created with mysql_connect().

Here is an example of how to use it.

  1. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

You can achieve the same effect with a simple MySQL query.

  1. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  2. $query = mysql_query('SELECT VERSION() as mysql_version');

Add new comment

The content of this field is kept private and will not be shown publicly.