What are the potential pitfalls of using SELECT * in SQL queries when fetching data for PHP scripts?

Using SELECT * in SQL queries can fetch unnecessary columns, leading to increased data transfer between the database and PHP scripts. This can result in slower query execution and higher memory usage. To optimize performance, it's better to explicitly specify the columns needed in the SELECT statement.

// Specify the columns needed in the SELECT statement instead of using SELECT *
$sql = "SELECT column1, column2, column3 FROM table_name WHERE condition";
$result = mysqli_query($connection, $sql);

// Fetch data from the result set
while ($row = mysqli_fetch_assoc($result)) {
    // Process data here
}