Prepared statement with PDO
PhpPlaceholders rather than interpolation. This is the whole of SQL injection defence in PHP.
$stmt = $pdo->prepare(
'SELECT id, title FROM posts WHERE author_id = ? AND published = ?'
);
$stmt->execute([$authorId, 1]);
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);