I'm running a stored procedure with sqlsrv_prepare(), while running same stored procedure directly onto the database I can see that there are rows returned. But running with sqlsrv_prepare() and checking no of rows returned via sqlsrv_num_rows() I get -1 returned.
function getSOLAIndexCheckReleaseStatusCount() {
global $dbConnection, $SOLAIndexCheckReleaseStatus;
$dbConnection= dbConnectSolaReplicaDBServer();
$query = "exec [SolaQC].[dbo].[sp_BinaryQC_IndexCheckReleaseStatus]";
$params = array();
$options = array( "Scrollable" => 'buffered',"QueryTimeout" => 480);
$result = sqlsrv_prepare( $dbConnection, $query,$params,$options);
if( $result === false ) {
//die( print_r( sqlsrv_errors(), true));
die("Something didn't go too smoothly! Try refreshing?");
}
$output = "";
if (!sqlsrv_execute($result)) {
//echo "Your code is fail!";
die(print_r( sqlsrv_errors(), true));
}
if ($result) {
$check_empty = sqlsrv_has_rows($result);
if ($check_empty == true) {
$output.= sqlsrv_num_rows($result);
}
else {
$output.= sqlsrv_num_rows($result);
}
}
return $output;
}
Below is the expected results:
I am not sure why sqlsrv_num_rows() doesn't return result in PHP. Can someone point me in the right direction?
FYI - I am using Apache/2.4.37 (Win32) OpenSSL/1.1.1a PHP/7.3.0
I think there might be an issue with the last if statement. You can check here a documentation about the function you are using..