下面是一段早期php代码,由于php升级及sql server驱动升级
目前是php 5.2.14 + Sql serve 2008,所以有些用法不同了,像
$res = mssql_query($sql, $link);改为$res = sqlsrv_query($conn,$sql);但mssql_fetch_row不知道如何改?就这是句怎么改?
                while ($row = mssql_fetch_row($res)){
                        $vals[strtolower(str_replace($search, '', $row[0]))] = (empty($row[1]) ? '0' : $row[1]);
                }
                #$res = mssql_query($sql, $link);
$res = sqlsrv_query($conn,$sql);                $search = array(' ', '/sec', '(KB)', '/', '-');                while ($row = mssql_fetch_row($res)){
                        $vals[strtolower(str_replace($search, '', $row[0]))] = (empty($row[1]) ? '0' : $row[1]);
                }                $vals['buffercachehitratio'] = $vals['buffercachehitratio'] / $vals['buffercachehitratiobase'] * 100;
                $vals['logcachehitratio'] = $vals['logcachehitratio'] / $vals['logcachehitratiobase'] * 100;
                $vals['proccachehitratio'] = $vals['cachehitratio'] / $vals['cachehitratiobase'] * 100;
                $vals['memoryhitratio'] = $vals['totalservermemory'] / $vals['targetservermemory'] * 100;                unset($vals['buffercachehitratiobase'], $vals['logcachehitratiobase'], $vals['cachehitratiobase'], $vals['cachehitratio']);

解决方案 »

  1.   

    while ($row = mssql_fetch_row(sqlsrv_fetch_array($res, SQLSRV_FETCH_NUM))){
      

  2.   

    while ($row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUM)){
      

  3.   

    ....总算是打对了
    while ($row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC){
      

  4.   

    to hnxxwyq:
    谢谢,不过报错:Call to undefined function mssql_fetch_row() 这个函数mssql_fetch_row应该也变了,我没查到。
      

  5.   

    谢谢,我目前整个文件还是调试不成功,按照hnxxwyq方法改了,还有其它错误。
    hnxxwyq能确定3楼和原代码同样的意思吗?另外,这句该怎么改呢?
    list($server_version) = mssql_fetch_row(mssql_query("SELECT SERVERPROPERTY('productversion')"));谢谢
      

  6.   

    while ($row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC)){
                            $vals[strtolower(str_replace($search, '', $row[0]))] = (empty($row[1]) ? '0' : $row[1]);
                    }// 这里这样打呢?
    var_dump($vals);exit;
      

  7.   

    mssql_query(xxx) =>sqlsrv_query(xxx) mssql_fetch_row(xxx) => sqlsrv_fetch_array(xxx, SQLSRV_FETCH_NUMERIC)
      

  8.   

    我这句改的没关题啊:
    list($server_version) = mssql_fetch_row(mssql_query("SELECT SERVERPROPERTY('productversion')"));
    改为:
    list($server_version) = sqlsrv_fetch_array(sqlsrv_query($conn,"SELECT SERVERPROPERTY('productversion')"),SQLSRV_FETCH_NUMERIC);可就是一直报:
    sqlsrv_query() expects parameter 1 to be resource, boolean given in xxx\scripts\ss_win_mssql.php on line 54
      

  9.   

    hi hnxxwyq , ths for your help.