How can PHP developers optimize SQL queries to reduce server load?

PHP developers can optimize SQL queries to reduce server load by using indexes on frequently queried columns, avoiding SELECT * queries and only selecting the necessary columns, using parameterized queries to prevent SQL injection attacks, minimizing the number of queries by combining them when possible, and caching query results to reduce database calls.

// Example of optimizing SQL query by using indexes and selecting only necessary columns
$query = "SELECT id, name FROM users WHERE email = :email";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':email', $email);
$stmt->execute();

// Fetching results
while ($row = $stmt->fetch()) {
    echo $row['id'] . ' ' . $row['name'];
}