title: SQLSRV query to array
body: <p>I try to query a SQL database and save data into a custom array, but the array always repeats last <code>row*num</code> rows on database.</p>
  
  <p>php:</p>
  
  <pre><code>class Cst
  {
      public $ParagemID;
      public $Designacao;
      public $DecimalDeGrauY;
      public $DecimalDeGrauX;
  }
  
  require 'config.php';
  $dsn = array( "Database"=&gt;"$database", "UID"=&gt;"$username", "PWD"=&gt;"$password", "LoginTimeout"=&gt; 60);
  $db = sqlsrv_connect($server, $dsn);
  
  $sql = "SELECT ParagemID, Designacao, DecimalDeGrauY, DecimalDeGrauX FROM adoParagens WHERE ParagemID &gt;= 20000"; 
  
  $stmt = sqlsrv_query($db, $sql); 
  
  $locations = new Cst();
  $location=array();
  $i=0;
  while( $row = sqlsrv_fetch_object($stmt)) 
  { 
      $locations-&gt;ParagemID = $row-&gt;ParagemID;
      $locations-&gt;Designacao = $row-&gt;Designacao;
      $locations-&gt;DecimalDeGrauY = $row-&gt;DecimalDeGrauY;
      $locations-&gt;DecimalDeGrauX = $row-&gt;DecimalDeGrauX;
      //echo json_encode($locations);
  
      $location[$i]= $locations;
      $i++;
  }
  echo json_encode($location);
  </code></pre>