title: sql server data to json using php
body: <p>My json code doesn't display anything, I have already tried many codes but nothing has helped. </p>
  
  <pre><code>include('connect.php');
  $sql = "SELECT *  FROM items";  
  $stmt = sqlsrv_query( $conn, $sql);
  
  if( $stmt === false)
  {
     echo "Error in query preparation/execution.\n";  
     die( print_r( sqlsrv_errors(), true));  
  }
  
  while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))  //this loop is working
  {    
    echo $row['item_id'].", ".$row['item_name'].", ".$row['Barcode']."&lt;br&gt;"; 
  }
  
  $json = array();
  do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
       $json[] = $row;
     }
  } while ( sqlsrv_next_result($stmt) );
  
  echo json_encode($json);  //empty?!
  sqlsrv_free_stmt( $stmt);
  </code></pre>