The removed mysql_num_rows() function returned the number of rows in a legacy result resource. In current code, choose the counting method based on what you actually need.
<?php
// Historical only: removed from PHP 7+
$query = mysql_query('SELECT * FROM student');
$number = mysql_num_rows($query);
?>
SELECT COUNT(*) AS total
FROM student;
<?php
$total = $dbo->query(
'SELECT COUNT(*) FROM student'
)->fetchColumn();
echo 'Total records = ' . $total;
?>
<?php
$stmt = $dbo->prepare(
'SELECT COUNT(*) FROM student WHERE class = :class'
);
$stmt->execute(['class' => 'Four']);
$total = (int) $stmt->fetchColumn();
?>
<?php
$result = $connection->query(
'SELECT id, name FROM student'
);
echo $result->num_rows;
?>
PDOStatement::rowCount() as the general way to count rows returned by a SELECT query. Use SQL COUNT(*) when the count itself is the result you need.Related: SQL COUNT(), SELECT, WHERE filtering, affected rows after data changes, and result column count.
For application-level examples, see PDO row-count notes, MySQLi num_rows, and PHP pagination. Row counts are also commonly needed after INSERT, UPDATE, and DELETE, but those data-change operations use affected-row semantics rather than SELECT result-row counting.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.