What are the potential pitfalls of using "SELECT *" in SQL queries, and what are some best practices for avoiding them?

Using "SELECT *" in SQL queries can lead to performance issues and potential security vulnerabilities. It can retrieve unnecessary columns, resulting in increased data transfer and processing time. To avoid these pitfalls, it is recommended to explicitly list the columns needed in the SELECT statement.

// Avoid using SELECT * in SQL queries
$sql = "SELECT column1, column2, column3 FROM table_name WHERE condition = 'value'";
$result = mysqli_query($conn, $sql);

// Process the query result
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process each row
    }
}