This function cannot be relied on to report errors since both a existence negative and a SQL error will report the same boolean value.
PHP - Manual: sqlsrv_has_rows
2024-11-14
(No version information available, might only be in Git)
sqlsrv_has_rows — Indicates whether the specified statement has rows
$stmt
): boolIndicates whether the specified statement has rows.
Returns true
if the specified statement has rows and false
if the statement
does not have rows or if an error occurred.
示例 #1 sqlsrv_has_rows() example
<?php
$server = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" );
$conn = sqlsrv_connect( $server, $connectionInfo );
$stmt = sqlsrv_query( $conn, "SELECT * FROM Table_1");
if ($stmt) {
$rows = sqlsrv_has_rows( $stmt );
if ($rows === true)
echo "There are rows. <br />";
else
echo "There are no rows. <br />";
}
?>
官方地址:https://www.php.net/manual/en/function.sqlsrv-has-rows.php