Good day! there was a task to transfer a small project from php + mysql to iis 8 + mssql, buried in the wall with the following line:

while($myrow = mysql_fetch_assoc($result)) { if ($myrow['mesto'] != $ip_user) { $mesto = $myrow['mesto']; echo '<option value="'.$mesto.'">'.$mesto.'</option>'; }; }; 

Redid in

 while($myrow = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)) { if ($myrow['mesto'] != $ip_user) { $mesto = $myrow['mesto']; echo '<option value="'.$mesto.'">'.$mesto.'</option>'; }; }; 

But I get this error in the log:

sqlsrv_fetch_array () expects parameter 1 to be resource, boolean given in

in line

 while($myrow = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)) 

What am I doing wrong ?

Marked as a duplicate by participants Alexey Shimansky , fori1ton , aleksandr barakin , Community Spirit 2 Feb '17 at 2:03 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Your request failed and $result not a resource, but false - rjhdby
  • Before fetch, check the number of records received. And it is better to remake PDO and never do it again. - ilyaplot
  • Yes, there was an error in the syntax of the request. Thank! - Madushko

1 answer 1

You pass the $ result -> true / false value to the sqlsrv_fetch_array function. And should transfer object of the fulfilled request.