title: Sqlsrv_field_metadata with name and type
body: <p>Working on converting my mysql php code to sqlsrv, but having issue how to grap the type and name with sqlsrv_field_metadata.</p>
  
  <p>This is the code: EDIT ( I have pasted the whole code here)</p>
  
  <pre><code> $sql = "
      SELECT tasks.title as Oppgaver, routines.value as Verdi, DATE_FORMAT(routines.date, '%d/%m/%Y') as Dato, routines.time as Tid, emps.user_name as Ansatt
      FROM routines, task_routine, tasks, emps
      WHERE routines.id = task_routine.routine_id
      AND task_routine.task_id = tasks.id
      AND (tasks.title  Like 'C_%') AND routines.emp_id=emps.id 
      ORDER BY routines.date, routines.time";
    }
  
  
  
   $result=sqlsrv_query($conn,$sql) or die("Couldn't execute query:&lt;br&gt;" . sqlsrv_error(). "&lt;br&gt;" . sqlsrv_errno()); 
  
  
  $file_ending = "xls";
  $reals=array();
  //header info for browser
  header("Content-Type: application/xls");    
  header("Content-Disposition: attachment; filename=$filename.xls");  
  header("Pragma: no-cache"); 
  header("Expires: 0");
  /*******Start of Formatting for Excel*******/   
  //define separator (defines columns in excel &amp; tabs in word)
  $sep = "\t"; //tabbed character
  
  //start of printing column names as names of MySQL fields
  
  /*for ($i = 0; $i &lt; sqlsrv_num_fields($result); $i++) {
      $type = sqlsrv_field_metadata($result,$i);
      echo sqlsrv_field_metadata($result,$i) . "\t";
      if ($type == "real")
      {
          $reals[] = $i;
      }
  }*/
  
  $metaData = sqlsrv_field_metadata($result);
  
  for ($i = 0; $i &lt; $metaData; $i++) {
     $type = $metaData[$i]["Type"];
     echo $metaData[$i]["Name"] . "\t";
     if ($type === SQL_REAL) {
        $reals[] = $i;
     }
  }
  
  
  print("\n");    
  //end of printing column names  
  //start while loop to get data
  while($row = sqlsrv_num_rows($result))
  {
      $schema_insert = "";
      for($j=0; $j&lt;sqlsrv_num_fields($result);$j++)
      {
          if(!isset($row[$j]))
              $schema_insert .= "NULL".$sep;
          elseif ($row[$j] != ""){
              if (in_array($j, $reals)){
                  $schema_insert .= str_replace(".",",","$row[$j]").$sep;
              } else {
                  $schema_insert .= "$row[$j]".$sep;
              }
          }
          else
              $schema_insert .= "".$sep;
      }
      $schema_insert = str_replace($sep."$", "", $schema_insert);
      $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
      $schema_insert .= "\t";
      print(trim($schema_insert));
      print "\n";
  
  } 
  </code></pre>
  
  <p>MYSQL ( WHICH WORKS)</p>
  
  <pre><code>$sql = "
  SELECT measurements.title as Maling, routines.value as Verdi, DATE_FORMAT(routines.date, '%d/%m/%Y') as Dato, routines.time as Tid, pools.name as Basseng, emps.user_name as Ansatt
  FROM routines, measure_routine, measurements, pools, emps
  WHERE routines.id = measure_routine.routine_id
  AND measure_routine.measure_id = measurements.id
  AND (measurements.title  Like 'T_%') AND measure_routine.pool_id=pools.id AND routines.emp_id=emps.id 
  ORDER BY routines.date, routines.time;
  
  ";
  $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:&lt;br&gt;" . mysql_error() . "&lt;br&gt;" . mysql_errno());
  //select database   
  $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:&lt;br&gt;" . mysql_error(). "&lt;br&gt;" . mysql_errno());   
  //execute query 
  $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:&lt;br&gt;" . mysql_error(). "&lt;br&gt;" . mysql_errno());    
  $file_ending = "xls";
  $reals=array();
  //header info for browser
  header("Content-Type: application/xls");    
  header("Content-Disposition: attachment; filename=$filename.xls");  
  header("Pragma: no-cache"); 
  header("Expires: 0");
  /*******Start of Formatting for Excel*******/   
  //define separator (defines columns in excel &amp; tabs in word)
  $sep = "\t"; //tabbed character
  //start of printing column names as names of MySQL fields
  for ($i = 0; $i &lt; mysql_num_fields($result); $i++) {
      $type = mysql_field_type($result,$i);
      echo mysql_field_name($result,$i) . "\t";
      if ($type == "real")
      {
          $reals[] = $i;
      }
  }
  
  
  
  print("\n");    
  //end of printing column names  
  //start while loop to get data
  while($row = mysql_fetch_row($result))
  {
      $schema_insert = "";
      for($j=0; $j&lt;mysql_num_fields($result);$j++)
      {
          if(!isset($row[$j]))
              $schema_insert .= "NULL".$sep;
          elseif ($row[$j] != ""){
              if (in_array($j, $reals)){
                  $schema_insert .= str_replace(".",",","$row[$j]").$sep;
              } else {
                  $schema_insert .= "$row[$j]".$sep;
              }
          }
          else
              $schema_insert .= "".$sep;
      }
      $schema_insert = str_replace($sep."$", "", $schema_insert);
      $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
      $schema_insert .= "\t";
      print(trim($schema_insert));
      print "\n";
  }
  </code></pre>
  
  <p>I searched on the docoumentation but didn't found out how: <a href="http://msdn.microsoft.com/en-us/library/cc296197.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/cc296197.aspx</a></p>