What function should be used to check the number of rows returned by a MySQL query in PHP?
To check the number of rows returned by a MySQL query in PHP, you can use the `mysqli_num_rows()` function. This function returns the number of rows in a result set. You can use it to determine if any rows were returned by your query and take appropriate actions based on the result.
// Assuming $conn is your MySQL database connection and $query is your SQL query
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0) {
// Rows were returned by the query
echo "Number of rows returned: " . mysqli_num_rows($result);
} else {
// No rows were returned
echo "No rows returned";
}
Related Questions
- Are there any potential pitfalls or best practices to consider when deciding between include and function in PHP?
- What are the potential security risks of using user@domain authentication in PHP scripts?
- How can the issue of a script only being executed once, even though there are two statements in the IF condition, be resolved in PHP?