What are the security concerns related to using SELECT * in PHP queries and how can they be mitigated?

Using SELECT * in PHP queries can pose security risks such as exposing sensitive data or potential SQL injection attacks. To mitigate these risks, it is recommended to explicitly specify the columns you want to retrieve in the SELECT statement rather than using SELECT *.

// Specify the columns you want to retrieve in the SELECT statement
$query = "SELECT column1, column2, column3 FROM table_name WHERE condition = :condition";

// Prepare and execute the query using PDO
$stmt = $pdo->prepare($query);
$stmt->bindParam(':condition', $condition);
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll();