SQL Injection Prevention

Comments criticize constructing SQL queries via string concatenation or interpolation with user input due to SQL injection risks, strongly advocating for prepared statements and parameterized queries as the safe alternative.

➡️ Stable 0.5x Security
2,525
Comments
20
Years Active
5
Top Authors
#6037
Topic ID

Activity Over Time

2007
2
2008
22
2009
57
2010
58
2011
148
2012
130
2013
139
2014
136
2015
111
2016
174
2017
130
2018
89
2019
128
2020
139
2021
269
2022
228
2023
195
2024
145
2025
221
2026
4

Keywords

e.g PHP PDO VALUES postgres.com ISAM SQL XML BLOBS ORM sql statements prepared queries injection sql injection query escaping strings orm

Sample Comments

unshift Nov 29, 2010 View on HN

nice to see people are still oblivious to sql injection and using string interpolation instead of prepared statements.

sethgecko Feb 16, 2018 View on HN

Am I the only one that finds it ridiculous that the way to query for data in SQL is by passing a string?

woah Jun 26, 2016 View on HN

Don't parameterized queries provide all the safety one might need?

dvh Dec 25, 2025 View on HN

It's 2025 why are you gluing SQL strings? Don't even use it as an example!

mirekrusin Aug 31, 2017 View on HN

Author is confusing prepared statements with parameterized queries/escaping in one of the first points. Prepared statements are not related to sql injections, ie. you can build them from interpolated strings as well.

bitexploder Apr 17, 2020 View on HN

For every person that gets SQL strong concatenation right 20 get it wrong. And there are simple and safe ways to write arbitrary SQL queries without using concatenation. Parmeterized queries are available everywhere. There is a reason we tell everyone not to do it and that reason is that it’s dangerous and almost everyone screws it up. I have found your case to be the exception in 13 years as an infosec researcher and consultant.

spullara Aug 31, 2022 View on HN

People are still constructing SQL statements using user provided data? Have they never used prepared statements before?

WrtCdEvrydy Mar 3, 2021 View on HN

honestly, use prepared statements...You get the same benefit of "template literals" but the data and query are separated at the DB level. The DB knows what is data and what is query therefore any attempt at escaping from SQL will be quashed there.

jkaplowitz Jun 28, 2023 View on HN

If you’re just worried about injection, you just need to use bound parameters instead of string interpolation. Boom, avoided at the database driver level even with plain sql. I admit though that some cases of string interpolation can be harder to catch in your code than when using ORMs.

bartonfink Mar 3, 2011 View on HN

Yup. And, if you're writing anything that talks to a database, use a parameterized statement (sometimes called a prepared statement) instead of just concatenating strings. You will blow it if you concatenate strings and that's what we call SQL injection.