How can count() and mysql_num_rows() functions be utilized in PHP to count MySQL data?

To count MySQL data in PHP, you can use the count() function to count the number of elements in an array returned by a MySQL query, or you can use the mysql_num_rows() function to directly count the number of rows in a result set.

// Using count() function
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
$row_count = count(mysqli_fetch_all($result, MYSQLI_ASSOC));
echo "Number of rows: " . $row_count;

// Using mysql_num_rows() function
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
$row_count = mysql_num_rows($result);
echo "Number of rows: " . $row_count;