Prepared Statement
A prepared statement is SQL with ? placeholders: SELECT * FROM students WHERE roll = ?. You send the number separately. The server reuses the plan. More important: it does not glue user text into SQL — that is how you stop SQL injection.
In PHP: mysqli prepare + bind_param. PDO: prepare + execute. In Java: PreparedStatement. Never: "WHERE name = '" + userInput + "'".
PREPARE stmt FROM 'SELECT name FROM students WHERE roll = ?'; EXECUTE stmt USING @r; DEALLOCATE PREPARE stmt; is the SQL-only form.
Trap: escaping quotes by hand and calling it ‘safe’. Trap: prepared statement for a table name (you cannot bind identifiers — whitelist them).
On the example next to this theory: Prepared Statement: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
WHERE roll = ? and bind 12. Never glue user text into SQL.