An SQL statement is considered closed when you have consumed all the results or closed the statement. Here is an example that both consumes the results and closes the statement.
$conn = sqlsrv_connect($server, $options);
if ( ($stmt = sqlsrv_query($conn, $statement)) )
{
do
{
$rows += sqlsrv_rows_affected($stmt);
// other statements
} while ( sqlsrv_next_result($stmt) ) ;
sqlsrv_free_stmt($stmt);
}
Rob