views:

47

answers:

4

Okay, so I'm getting my MySQL Version like so:

preg_replace('#[^0-9\.]#', '', mysql_get_server_info());

Which gives me a number like: 5.1.36

That's all good. What I need to do, is compare that version with another version. I was about to attempt to write my function to compare them, when I thought of version_compare(). However, upon testing I became unsure, but perhaps I'm just not sure how MySQL Version Numbers work.

This is what I tested:

version_compare('5.1.36', '5.1.4', '<');

or

5.1.36 < 5.1.4

I assumed that this would return true, that 5.1.36 is less than 5.1.4. My reason for that is, I figure 5.1.4 is actually 5.1.40 not 5.1.04. Perhaps I'm wrong there.

So am I thinking wrong, or is the function returning the incorrect result?

A: 

I assumed that this would return true, that 5.1.36 is less than 5.1.4. My reason for that is, I figure 5.1.4 is actually 5.1.40 not 5.1.04. Perhaps I'm wrong there.

Yes, 5.1.36 is greater than 5.1.4.

Simon
+5  A: 

The function is correct. The numbering system is M.m.r where each "number" is a decimal number.

  • M is the major version number
  • m is the minor version number
  • r is the revision number

So 5.1.36 would be revision 36 of the 5.1 minor version... Therefore, 5.1.4 would be revision 4 (and hence 36 > 4)...

ircmaxell
Excellent. That sums it up very nicely for me. Something totally new to me. Thank you very much ircmaxell. :)
Jason Lewis
+1  A: 

http://www.php.net/manual/en/mysqli.get-server-version.php

mysqli's get_server_version() method will return the version as an integer.

main_version * 10000 + minor_version * 100 + sub_version (i.e. version 4.1.0 is 40100).

simplemotives
Jason Lewis is using `mysql_get_server_info` and not `mysqli_get_server_version`.
Gumbo
A: 

http://php.net/version_compare :)

Col. Shrapnel