diff --git a/source/shared/core_results.cpp b/source/shared/core_results.cpp index fd7209610..67c82e0e0 100644 --- a/source/shared/core_results.cpp +++ b/source/shared/core_results.cpp @@ -907,7 +907,12 @@ SQLLEN sqlsrv_buffered_result_set::row_count( TSRMLS_D ) { last_error = NULL; - return zend_hash_num_elements( cache ); + if ( cache ) { + return zend_hash_num_elements( cache ); + } + else { + return -1; + } } // private functions diff --git a/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt b/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt new file mode 100644 index 000000000..a9e3040ed --- /dev/null +++ b/test/sqlsrv/srv_330_numrow_null_buffered_result_set.phpt @@ -0,0 +1,31 @@ +--TEST-- +GitHub issue #330 - get numrow of null buffered result set +--DESCRIPTION-- +A variation of the example in GitHub issue 330. A -1 value returned as numrow of a null buffered result set. +--SKIPIF-- +--FILE-- + SQLSRV_CURSOR_CLIENT_BUFFERED]); + +if ($stmt) { + $hasRows = sqlsrv_has_rows($stmt); + $numRows = sqlsrv_num_rows($stmt); + echo "hasRows: "; + var_dump($hasRows); + echo "numRows: "; + var_dump($numRows); +} +?> +--EXPECT-- +hasRows: bool(false) +numRows: int(-1) \ No newline at end of file