Get MySQL version using PHP

Many web based applications need to know what version of MySQL they are using. Fortunately MySQL has a built in command that will return the version as part of a query. Just enter the following command at the MySQL prompt and the server will return the version.

mysql_version1.gif

If you’re needing to get the version from inside a PHP script you can use the following code after connecting to the database server.

PHP:
  1. rs = mysql_query(“SELECT VERSION()”);
  2. $row = mysql_fetch_row($rs);
  3. echo $row[0];

Of course you can have $row[0] set to any variable you want to use rather than just echoing it back.

Question, Comments...

Do you have more questions. Please either leave a comment below or join us in our new forum.

Leave a Reply