What best practices should PHP developers follow when designing database schemas and writing SQL queries to maintain data integrity and optimize performance in a web application?

To maintain data integrity and optimize performance in a web application, PHP developers should follow best practices such as normalizing the database schema, using indexes efficiently, avoiding nested queries, and utilizing prepared statements to prevent SQL injection attacks.

// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$user = $stmt->fetch();