What are the advantages of using "SELECT COUNT(*)" instead of "SELECT * FROM table_name" when counting records in a table in PHP?

When counting records in a table in PHP, using "SELECT COUNT(*)" is more efficient than "SELECT * FROM table_name" because it only retrieves the count of records without fetching all the data. This can significantly improve performance, especially when dealing with large datasets. Additionally, using "SELECT COUNT(*)" is more concise and clearer in its purpose, as it explicitly indicates that you are only interested in the count of records.

// Using "SELECT COUNT(*)" to count records in a table
$query = "SELECT COUNT(*) FROM table_name";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
$count = $row[0];
echo "Total records: " . $count;