Why is it recommended to avoid using SELECT * in SQL queries and instead specify the columns to retrieve when working with PDO in PHP?

When using PDO in PHP, it is recommended to avoid using SELECT * in SQL queries because it can lead to performance issues and potential security vulnerabilities, as it retrieves all columns from a table, even those that are not needed. Instead, specifying the specific columns to retrieve can improve query performance and reduce the risk of exposing sensitive data.

// Specify the columns to retrieve instead of using SELECT *
$stmt = $pdo->prepare("SELECT column1, column2 FROM table_name WHERE condition = :condition");
$stmt->bindParam(':condition', $condition_value);
$stmt->execute();