S
Seoffix.com
Sign In Get Pro Membership

PHP 8 Server-Side

PHP PDO Query

Intermediate PHP 40 XP

PHP PDO Query

A prepared statement keeps user input out of the SQL text, which blocks injection.

Example

<?php
$stmt = $pdo->prepare("SELECT * FROM posts WHERE id = ?");
$stmt->execute([5]);

Your task

Prepare a query for a user by id, execute it with [1] and fetch all rows.

Hints

  1. prepare() first, then execute()
  2. fetchAll() returns every row

Check your understanding

Answer every question to pass.
1. Why use a prepared statement?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 40 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP