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条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题