title: Strange error "sqlsrv_fetch_array(): 16 is not a valid ss_sqlsrv_stmt resource" since ReturnDatesAsStrings
body: <p>I am using the sqlsrv driver for IIS so I can connect to a MS SQL server in PHP.</p>
  
  <p>I've managed to convert a lot of my original mysql_ code and all going well, until I tried to SELECT some DateTime fields from the database. They were coming back as Date objects in PHP rather than strings, I found the fix which is adding this to the connection array:</p>
  
  <p>'ReturnDatesAsStrings'=>1</p>
  
  <p>Since doing that though my code is broken when trying to populate my recordset:</p>
  
  <pre><code>    function row_read($recordset) {
  
      if (!$recordset) {
          die('&lt;br&gt;&lt;br&gt;Invalid query :&lt;br&gt;&lt;br&gt;&lt;bold&gt;' . $this-&gt;sql . '&lt;/bold&gt;&lt;br&gt;&lt;br&gt;' . sqlsrv_error());
      }
  
      $rs = sqlsrv_fetch_array($recordset);
      return $rs;
  }
  </code></pre>
  
  <p>The error is: sqlsrv_fetch_array(): 16 is not a valid ss_sqlsrv_stmt resource</p>
  
  <p>There is such little amount of help on that error in Google so this is my only shot! I just don't get it.</p>
  
  <p>row_read is called from within a While: while ($row = $db->row_read($rs)) {</p>
  
  <p>Any ideas?</p>
  
  <p>Just to add more code and logic - I do a simple SELECT of all my orders, then as it loops through them, I do another 2 SELECT's on the orders table then the customer table. It's falling down when I try these extra 2 'gets':</p>
  
  <pre><code>        $this-&gt;db-&gt;sql = "SELECT * FROM TicketOrders";  
  
      $rs = $this-&gt;db-&gt;query($this-&gt;db-&gt;sql);
  
      $this-&gt;htmlList-&gt;path("skin/search.bookings");
  
      if ($this-&gt;db-&gt;row_count != 0) {
          while ($row = $this-&gt;db-&gt;row_read($rs)) {
  
              // Load the order row
              $this-&gt;TicketOrders-&gt;get($this-&gt;db, $row['Id']);                
  
              // Load the customer row
              $this-&gt;Customers-&gt;get($this-&gt;db, $row['CustomerId']);
  </code></pre>