--TEST-- first result is consumed without calling next_result, the next result is made available by calling next_result --SKIPIF-- --FILE-- "$databaseName", "UID"=>"$uid", "PWD"=>"$pwd"); $conn = sqlsrv_connect( $server, $connectionInfo); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } /*revert inserts from previous tests*/ $d_sql = "DELETE FROM Production.ProductReview WHERE EmailAddress!='john@fourthcoffee.com' AND ProductID=709"; $stmt = sqlsrv_query($conn, $d_sql); /* Drop the stored procedure if it already exists. */ dropProc($conn, 'InsertProductReview'); /* Create the stored procedure. */ $tsql_createSP = " CREATE PROCEDURE InsertProductReview @ProductID int, @ReviewerName nvarchar(50), @ReviewDate datetime, @EmailAddress nvarchar(50), @Rating int, @Comments nvarchar(3850) AS BEGIN INSERT INTO Production.ProductReview (ProductID, ReviewerName, ReviewDate, EmailAddress, Rating, Comments) VALUES (@ProductID, @ReviewerName, @ReviewDate, @EmailAddress, @Rating, @Comments); SELECT * FROM Production.ProductReview WHERE ProductID = @ProductID; END"; $stmt = sqlsrv_query( $conn, $tsql_createSP); if( $stmt === false) { echo "Error in executing statement 2.\n"; die( print_r( sqlsrv_errors(), true)); } /*-------- The next few steps call the stored procedure. --------*/ /* Define the Transact-SQL query. Use question marks (?) in place of the parameters to be passed to the stored procedure */ $tsql_callSP = "{call InsertProductReview(?, ?, ?, ?, ?, ?)}"; /* Define the parameter array. */ $productID = 709; $reviewerName = "Morris Gogh"; $reviewDate = "2008-02-12"; $emailAddress = "customer@email.com"; $rating = 3; $comments = "[Insert comments here.]"; $params = array( $productID, $reviewerName, $reviewDate, $emailAddress, $rating, $comments ); /* Execute the query. */ $stmt = sqlsrv_query( $conn, $tsql_callSP, $params); if( $stmt === false) { echo "Error in executing statement 3.\n"; die( print_r( sqlsrv_errors(), true)); } echo "

"; /* Consume the first result (rows affected by INSERT query in the stored procedure) without calling sqlsrv_next_result. */ echo "Rows affectd: ".sqlsrv_rows_affected($stmt)."-----\n"; echo "

"; /* Move to the next result and display results. */ $next_result = sqlsrv_next_result($stmt); if( $next_result ) { echo "

"; echo "\nReview information for product ID ".$productID.".---\n"; while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) { echo "
ReviewerName: ".$row['ReviewerName']."\n"; echo "
ReviewDate: ".date_format($row['ReviewDate'], "M j, Y")."\n"; echo "
EmailAddress: ".$row['EmailAddress']."\n"; echo "
Rating: ".$row['Rating']."\n\n"; } } elseif( is_null($next_result)) { echo "

"; echo "No more results.\n"; } else { echo "Error in moving to next result.\n"; die(print_r(sqlsrv_errors(), true)); } dropProc($conn, 'InsertProductReview', false); /* Free statement and connection resources. */ sqlsrv_free_stmt( $stmt ); sqlsrv_close( $conn ); ?> --EXPECT--

Rows affectd: 1-----

Review information for product ID 709.---
ReviewerName: John Smith
ReviewDate: Sep 18, 2013
EmailAddress: john@fourthcoffee.com
Rating: 5
ReviewerName: Morris Gogh
ReviewDate: Feb 12, 2008
EmailAddress: customer@email.com
Rating: 3