dongqiu3254 2019-04-24 16:14
浏览 99
已采纳

Mssql获取数组在while循环中显示错误

I'm write a query for take some result in mssql server ,that working but now they some errors ,the error is

Warning: mssql_fetch_array(): 3 is not a valid MS SQL-result resource in

my connection query is working and there is no problem, my query like this

$qry="select cd_pcp,pcp_nm from tbl_m_pcp order by cd_pcp asc";
$result=mssql_query($qry);
while($row1=mssql_fetch_array($result))
{
echo $row1['cd_pcp'];
}

var_dump the $result show

resource(3) of type (mssql result)

the query is execute in sql-server whyshow this type error any way to solve this issue please help me?

  • 写回答

2条回答 默认 最新

  • duangangpin078794 2019-04-24 17:19
    关注

    One possible explanation is the return value from mssql_query():

    Return Values

    Returns a MS SQL result resource on success, TRUE if no rows were returned, or FALSE on error.

    It's important to check the result from mssql_query():

    <?php
    ...
    $qry = "select cd_pcp,pcp_nm from tbl_m_pcp order by cd_pcp asc";
    $result = mssql_query($qry);
    if ($result === true) {
        echo "No rows are selected";
    } else if ($result === false) {
        echo "Error. ".mssql_get_last_message();
        exit;
    } else {
        while ($row1 = mssql_fetch_array($result)) {
            echo $row1['cd_pcp'];
        }
    }
    ...
    ?>
    

    Notes:

    MSSQL extension was removed in PHP 7.0. One good option is PHP Driver for SQL Server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败