Parameterized query meaning, in plain words

A parameterized query (placeholder) passes the command and input values to the database separately. What OWASP says it prevents and how to use it with care.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

A placeholder, also called a parameterized query, is a way of passing the command and the input values to the database separately. A placeholder is a temporary mark set where a value will go. OWASP lists parameterized queries as a way to prevent SQL injection, the attack in which input typed into a form is used to alter a database command.

How does a parameterized query work?

Think of a standard application form at a government office. The wording is printed in advance, and the applicant fills in only the blanks. Whatever is written in a blank, the printed wording does not change.

A placeholder has the same design. The template of the command sent to the database holds only a temporary mark where a value goes, and the actual values are sent separately. OWASP says a bind variable tells the database that the input is data and can never become a command.

As a result, what a user types is much less likely to rewrite how the command is put together. The command keeps the shape its author gave it, and the input stays in the blank. The whole picture of SQL injection is on the SQL injection vulnerability page. The free URL check shows only the outside of your site and cannot tell whether your database queries are built safely.

Why do parameterized queries matter?

SQL injection arises from a design in which input values are mixed into the command as it is built. OWASP says parameterized queries are the best defense against this problem.

Take care in how you use them. OWASP warns that many libraries offer parameterization but often build the query by joining strings internally. The step that passes the values separately has to take place on the server side. Using a library that offers parameterization is therefore not proof in itself that the values are really passed apart.

If SQL is built dynamically inside a stored procedure, a procedure registered on the database side, the same weakness comes back. In that case too, you use a mechanism that passes the values separately. So the rule is not about which feature you call but about keeping command and values apart at every point where SQL is assembled. How this differs from checking input is explained in the input validation term page.

Related terms

  • SQL injection: an attack that abuses an input field to operate a database improperly
  • Input validation: checking that submitted data is what the application expects

Next step

How to find the weak point and how to fix it are on the SQL injection vulnerability page. The free URL check shows only what is visible from outside. To have the way your code is built reviewed, contact us.

Frequently asked questions

If I use placeholders, do I still need to check input?

You still do. OWASP says input validation alone cannot prevent SQL injection, but validation has its own job of reducing malformed data. Use both.

Are stored procedures safe?

Not automatically. OWASP says the same problem returns when SQL is built dynamically inside a stored procedure. In that case too, use a mechanism that passes values separately.

Frequently asked questions

If I use placeholders, do I still need to check input?

You still do. OWASP says input validation alone cannot prevent SQL injection, but validation has its own job of reducing malformed data. Use both.

Are stored procedures safe?

Not automatically. OWASP says the same problem returns when SQL is built dynamically inside a stored procedure. In that case too, use a mechanism that passes values separately.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.