What are the potential pitfalls of using SELECT * in SQL queries, and why is it recommended to list individual fields instead?

Using SELECT * in SQL queries can lead to performance issues, as it retrieves all columns from the table even if they are not needed. This can result in unnecessary data being transferred over the network and processed by the database server. It is recommended to list individual fields in the SELECT statement to only retrieve the necessary data, improving query performance and reducing resource consumption.

// Instead of using SELECT *, list individual fields in the query
$sql = "SELECT field1, field2, field3 FROM table_name WHERE condition = 'value'";
$result = mysqli_query($connection, $sql);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process data here
    }
} else {
    echo "No results found";
}