0

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?

Zhorov
  • 28,486
  • 6
  • 27
  • 52
Shambu
  • 73
  • 1
  • 9

2 Answers2

0

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.

Zhorov
  • 28,486
  • 6
  • 27
  • 52
0

I believe that var_dump will always return "mssql result" independent if the return is successful or not. To do the debugging test if the value is returning FALSE

$result = mssql_query($qry,$conn);
if(!$result)  {
   die('MSSQL error: ' . mssql_get_last_message());
}
Tom Lima
  • 1,027
  • 1
  • 8
  • 25