What are some best practices for structuring SQL queries in PHP applications to avoid performance issues?

When structuring SQL queries in PHP applications, it is important to use parameterized queries to prevent SQL injection attacks and improve performance. Additionally, avoid using SELECT * and instead specify the exact columns needed to reduce the amount of data retrieved from the database. Lastly, consider indexing columns that are frequently used in WHERE clauses to optimize query performance.

// Example of a parameterized query in PHP using PDO
$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$stmt = $pdo->prepare('SELECT column1, column2 FROM table WHERE id = :id');
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$results = $stmt->fetchAll();