Stack Exchange
SQL Server : fetch array does not work stored procedure
I execute a procedure in this php - what happens is that I get the result of how many columns are affected but does not show the records to consult
conn.php
$serverName = "server";
$connectioInfo = array("Database"=>"mydata", "UID"=>"user",
"PWD"=>"123","CharacterSet"=> "UTF-8");
$conn = sqlsrv_connect($serverName,$connectioInfo) or die(print_r( sqlsrv_errors(), true));

index.php
global $conn;

$tsql_callSP = "EXEC storedprocedure  ?, ?, ?";  
/* Define the parameter array. */  
$date1 = '1010';  
$date2= '1010';  
$number= 1;  
$params = array($date1 , $date2, $number);

$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);  

if( $stmt === false )  
{  
     echo "Error in statement execution.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  

/* Retrieve and display the first result. */  
echo "Query 1 result:\n";  
while( $row = sqlsrv_fetch_array( $stmt)) 
{   
     print_r($row);  
}  

/* Move to the next result of the batch query. */  
sqlsrv_next_result($stmt);  

/* Display the result of the second query. */  
echo "Query 2 result:\n";  
echo "Rows Affected: ".sqlsrv_rows_affected($stmt)."\n";  

/* Move to the next result of the batch query. */  
sqlsrv_next_result($stmt);  

/* Retrieve and display the third result. */  
echo "Query 3 result:\n";  
while( $row = sqlsrv_fetch_array($stmt))
{  
    echo "ProdID: ".$row['onecolumn']."\n";  
     echo "-----------------\n";   
}  

/* Free statement and connection resources. */  
sqlsrv_free_stmt( $stmt );  
sqlsrv_close( $conn);  
?>

Result

Query 1 result: Query 2 result: Rows Affected: 23 Query 3 result:

but it doesn't return my records

Have you tried using with pdo_sqlsrv and fetchall()?

This could be correct behavior if the stored procedure only contains delete, insert and/or update statements. Without stored procedure code in your question it's hard to say otherwise.

the procedure is only a query in several tables
