Prepared statement with PDO

Php

Placeholders 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);

More in PHP

Random picks