• PHP Help PHP Coding
  • [RESOLVED] Is there a way for script to "sniff" ver. of MySQL, and alter commands?

Hi there everyone,

During research on my problem concerning charsets and such, I've realized that I need to dictate collation on database tables, but can only do this in mysql4, as 3 doesn't allow the feature.

How would I determine MySQL version for the if/else to include collation?

thanks,
json

    [man]mysql_get_server_info[/man] or [man]mysqli_get_server_info[/man] as applicable.

      hi there nog,

      thanks very much for the reply. I note in the php docs that it states that it will produce a result like "4.0.1-alpha". Can I still use a >= condition with a result that is alpha-numeric?

      thanks,
      json

        If you just need the top-level version number (3, 4, or 5) you could use [man]intval/man to get it:

        $msyqlVersion = intval(mysql_get_server_info());
        

          Thanks very much for your help NogDog, that seems to have worked spectacularly.

          thanks,
          json

            For finer-grained comparisons, I think MySQL's version numbering is similar enough to PHP's that [man]version_compare[/man] can be used. At least, it recognises that '4.2.1-alpha' is earlier than '4.2.1'.

              Write a Reply...