3 rows. That is what a search for a nonexistent email returned from a query built by pasting input into the SQL text. The same search through a prepared statement returned 0 rows. SQL injection happens when an app pastes user input into the SQL text, so the database parses part of that input as SQL. Keep the template fixed and pass values through the binding API.

What the parser sees

The database decides the structure of a query from the SQL text it parses. Concatenated input takes part in parsing: a quote closes your string literal, and whatever follows is read as SQL. A placeholder changes that: preparation compiles the template with a parameter slot where ? stood, and binding supplies the value to that slot. Bound strings remain values and cannot become SQL.

The fix in PHP

Unsafe code pastes the email straight into the SQL string. Fixed code prepares a template and binds the value:

$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', $user, $pass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, ]); $stmt = $pdo->prepare('SELECT id, email FROM users WHERE email = ?'); $stmt->execute([$_GET['email']]); 

The MySQL driver emulates by default, so PDO quotes values and builds the SQL string on the client. With emulation off, the template and the values travel separately. The same pattern exists elsewhere: $1 in node-postgres and PreparedStatement in Java.

Our lab: 3 rows vs 0

We ran our lab on 2026-11-06 with PHP 8.5.2 and an in-memory SQLite database holding 3 throwaway users and 3 notes. Each input went once to each. A normal search returned 1 row on both. The crafted input x' OR '1'='1 returned 3 rows from string-built SQL and 0 from the prepared statement. A UNION payload also returned 3 rows and 0, carrying role and password hash columns in the search's own field slots. The numeric case needed no quote at all: 1 OR 1=1 returned all 3 notes from string-built SQL and 0 from the prepared statement.

What placeholders cannot do

A placeholder stands for a value. Table names, column names and keywords such as ASC are structure the database needs before any value is bound, so this is where string-built SQL tends to survive. Map the request to tokens your code owns and reject anything else: email to email, newest to created_at, asc to ASC, desc to DESC, rejecting the rest with a 400.

Escaping is not a substitute

OWASP marks manual escaping as strongly discouraged: rules depend on the database and its settings, and escaping only helps inside a quoted string. A numeric parameter has no quotes to escape, as the 1 OR 1=1 case shows. ORMs bind values for you, but their raw helpers are only safe when you pass values as bindings. Least privilege limits what a missed bug can reach.

Our take

Bind every value and map every structural choice to a fixed token. Then review whatever SQL your code still assembles from strings.

Full article, with the lab table and fix checklist: https://systemdesignsimple.com/what-is-sql-injection-and-how-to-prevent-it/