Is it best practice to always list out all columns in a SELECT statement instead of using SELECT * in PHP database queries?

It is generally considered best practice to list out all columns explicitly in a SELECT statement instead of using SELECT *. This is because using SELECT * can lead to performance issues, especially when unnecessary columns are retrieved. By listing out only the required columns, you can improve query performance and make your code more maintainable.

<?php
// Explicitly list out columns in the SELECT statement
$query = "SELECT column1, column2, column3 FROM table_name WHERE condition = 'value'";
$result = mysqli_query($connection, $query);

if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process the retrieved data
    }
} else {
    echo "Error: " . mysqli_error($connection);
}

mysqli_close($connection);
?>