🔐Parameterized Query
Also known as Prepared Statement, Bound Parameters, Placeholder Query
A query with blank spots for the data. What a user types can never become a command.
Think of it like
Think of it like a form with boxes. Whatever you write in a box stays in that box.
Example
Jack's login code used to glue the email into the SQL. He switches to a parameterized query, and a quote in an email is now just a quote.
Why it matters
Definition
Example code
python
cur.execute(
"SELECT * FROM users WHERE email = %s",
(email,),
)Common mistake
Key takeaways
- 1Command and data apart. They travel to the database separately.
- 2Blank spots. A ? or $1 marks where data goes.
- 3The library fills it. Never paste input in yourself.