Why prepared statements are mandatory
User input should never be concatenated into a query string. PDO prepared statements pass parameters separately and eliminate the risk of SQL injection.
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
$stmt->execute([':email' => $email]);Error handling
Never expose error details to users in production; catch them with ERRMODE_EXCEPTION and log them.
Connection management
Create a single PDO instance and share it across the application. Use persistent connections carefully, otherwise you may exceed the connection limit.