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?
Advertisement
Answer
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.