title: how to get an array of objects from sql query
body: <p>My code is</p>
  
  <pre><code>$sql = 'select * from table;' $res = $connection-&gt;query($sql);
  while($row = mysqli_fetch_row($res){'tackle output'};
  </code></pre>
  
  <p>to get an object</p>
  
  <pre><code>while($row = $res-&gt;fetch_object()){'tackle output'};
  </code></pre>
  
  <p><strong>Question:</strong> what do I have to do to get an array of objects, so my output is thus</p>
  
  <pre><code>$data[$row[0]]= fetch_object();
  </code></pre>