0

My application is using the following code to detect mysql higher than 5. It works well with PHP 5.2, 5.3 and 5.4.

The trouble is with PHP 5.5 which uses mysqlnd by default so the script reports mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4 $ and cannot detect MySQL properly. I need to make an exception for such version, but I don't know how to.

 echo "<mysql>";
    if(key_exists('mysql', $phpinfo))
    {
        if(key_exists('Client API version', $phpinfo['mysql']))
        {
            $t=explode(".", $phpinfo['mysql']['Client API version']);
            if($t[0]>=5)
                $ok=1;
        else
                $ok=0;
            echo "<val>{$phpinfo['mysql']['Client API version']}</val><ok>$ok</ok>";
        }
        else
           echo "<val></val><ok>0</ok>";
    }
    else
        echo "<val></val><ok>0</ok>";
    echo "</mysql>\n";
4

2 回答 2

2

请使用此 SQL 命令:

SHOW VARIABLES LIKE "%version%";

将显示如下内容:

在此处输入图像描述

于 2013-07-18T21:35:15.080 回答
0

您不应该mysql在 5.5 中使用。它已被弃用。

不推荐使用 mysql_ 函数

自 PHP 5.5.0起,以 开头的 PHP 函数mysql_已被弃用。如果您有能力这样做,请考虑更新您的代码以改用MySQLiPDO扩展。

无论如何,使用 mysqli (你的问题标签中似乎有)

phpinfo 键是:$phpinfo['mysqli']['Client API header version']而不是$phpinfo['mysql']['Client API version'].

于 2013-07-18T21:19:52.747 回答