It is because sqlsrv_query()
uses SQLSRV_CURSOR_FORWARD
cursor type by default. However, in order to get a result from sqlsrv_num_rows()
, you should choose one of these cursor types below:
- SQLSRV_CURSOR_STATIC
- SQLSRV_CURSOR_KEYSET
- SQLSRV_CURSOR_CLIENT_BUFFERED
For more information, check: Cursor Types (SQLSRV Driver)
In conclusion, if you use your query like:
$query = sqlsrv_query($conn, $result, array(), array( "Scrollable" => 'static' ));
you will get result in:
$row_count = sqlsrv_num_rows($query);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…