Prepared Statements
Run parameterized queries.
What Is a Prepared Statement
A prepared statement sends the SQL text to the database once to be parsed and planned, then executes it many times with different parameters. It is faster for repeated queries and safer against injection.
Parameter Placeholders
Never build SQL by concatenating user input. Use placeholders so the driver sends values separately. PostgreSQL uses $1, $2; MySQL and SQLite use ?.
SELECT * FROM users WHERE age > $1 AND city = $2All lessons in this course
- Opening a Connection
- Querying Rows
- Prepared Statements
- Transactions