What are potential pitfalls of using the "select *" statement in a MySQL query when displaying data in PHP?

Using the "select *" statement in a MySQL query can potentially lead to performance issues and security vulnerabilities, as it retrieves all columns from a table regardless of whether they are needed. To avoid these pitfalls, it is recommended to explicitly specify the columns to retrieve in the query.

<?php
// Connect to MySQL database
$conn = new mysqli($servername, $username, $password, $dbname);

// Query with specified columns
$sql = "SELECT column1, column2, column3 FROM table_name";
$result = $conn->query($sql);

// Display data
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Column 1: " . $row["column1"]. " - Column 2: " . $row["column2"]. " - Column 3: " . $row["column3"]. "<br>";
    }
} else {
    echo "0 results";
}

// Close database connection
$conn->close();
?>