title: How to loop through multiple result sets from stored procedure in PHP?
body: <p>Im slightly going out of my mind trying to get 3 result sets from a stored procedure (SP) in SQL server 2008. </p>
  
  <p><em><a href="http://pastebin.com/dnds3KGn" rel="nofollow">Stored procedure</a></em>: </p>
  
  <pre><code>CREATE PROCEDURE db_abbTest
  AS
  BEGIN
          SET NOCOUNT ON;
  
          SELECT 1
          SELECT 2
          SELECT 3
          RETURN 0
  END
  GO
  </code></pre>
  
  <p><a href="http://pastebin.com/PCHyQCJA" rel="nofollow"><em>PHP code</em></a>: </p>
  
  <pre><code>&lt;?php
  
  $serverName = "server";
  $connectionInfo = array("UID"=&gt; "user", "PWD" =&gt;"pass", "Database"=&gt;"sample_db");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  
  if( $conn )
  {
      $sql = "db_AbbTest";
      $r = sqlsrv_query($conn, $sql, null, array(
              'Scrollable' =&gt; SQLSRV_CURSOR_STATIC,
              'SendStreamParamsAtExec'    =&gt; true
          ));
      var_dump($r);
          while( $obj = sqlsrv_fetch( $r))
          {
                var_dump($obj);
                var_dump(sqlsrv_fetch_array($r));
          }
       echo "Connection established.\n";
  }
  else
  {
       echo "Connection could not be established.\n";
       die( print_r( sqlsrv_errors(), true));
  }
  
  /* Close the connection. */
  sqlsrv_close( $conn);
  </code></pre>
  
  <p>The SP returns three results (3x select statements) however i cannot seem to get all of the results back from the query. Any Ideas?
  I have tried <code>while(sqlsrv_fetch_object($r){//do something})</code>
  but no luck..</p>