I see this is an old question, but I was also looking for a solution to this. Came up with the following which works for me:
function mssql_query($conn, $query, array $bind = array()) {
$stmt = sqlsrv_query($conn, $query, $bind);
if( $stmt=== false ) {
// do something with the error information
// die(print_r(sqlsrv_errors(), true));
return array();
}
sqlsrv_execute($stmt);
$data = array();
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
array_push($data, $row);
}
return $data;
}
Which can be used directly in a foreach loop:
foreach(mssql_query($conn, $query) as $row) {
echo $row['column'];
}
Or assigned to a variable for counting etc.
$conn is of course the connection (from PHP.net):
$serverName = "server.example.com"; // remember to append instance if applicable
$connectionInfo = array( "Database"=>"dbname", "UID"=>"username", "PWD"=>"password" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}