PHP theorytheory 0/50 · 0%
Database · medium

27. PDO & Prepared Statements

Safe database access.

PDO (PHP Data Objects) provides a consistent interface for accessing multiple database systems. Prepared statements, created with $pdo->prepare() and executed with bound parameters, separate SQL logic from data, preventing SQL injection.

Using placeholders (either ? or :name) instead of concatenating user input directly into SQL strings is the standard safe practice for all database queries.

Check your understanding

  1. 1. What primarily protects against SQL injection when using PDO?

  2. 2. Which PDO method compiles a SQL statement with placeholders?