$sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); $num_rows = mysqli_num_rows($result); echo "Number of rows in 'users' table: " . $num_rows;
$sql = "SELECT * FROM orders WHERE customer_id = 10"; $result = $pdo->query($sql); $num_rows = $result->rowCount(); echo "Number of rows in 'orders' table where customer_id = 10: " . $num_rows;This example uses PDO to connect to the database and execute a SELECT query to retrieve all rows from the orders table that match the customer_id of 10. The rowCount() method of the PDOStatement object is then used to determine the number of rows that match the query condition. Package/Library: Both MySQLi and PDO are database extensions that are included with PHP by default. Therefore, no additional package or library is needed to use the getNumRows() function.