All over the internet you can find posts and tutorials saying these are two terms for the “exact same thing”.
In database management systems, a prepared statement or parameterized statement is a feature used to execute the same or similar database statements repeatedly with high efficiency.
Both parameterized queries and prepared statements are exactly the same thing. Prepared statement seems to be the more commonly used term, but there is no difference between both terms.
But is it really?
[php]$sth = $dbh->prepare('SELECT * FROM user WHERE id = ’ . $id);[/php]
This will be prepared and cached by the SQL server as ie “SELECT * FROM user WHERE id = ‘313’”. While it’s really useless to prepare a query like this - it’s still a prepared statement!
But we can all agree this is not what we mean when we say “use prepared statements” - so what do we mean? Generally we do not really consider (too much) the i[/i] performance gain on preparing statements.
We usually front it to combat SQL injection - hence what we’re really after are “parameterized queries”.
[hr]
Am I the only one who don’t think these are the same at all, and get frustrated as beginners might think they’re all good if they just prepare their unsafe query? Quite open to the possibility that I might be
I just know this is a problem that should have been solved ~10 years ago, we should make it as easy as possible to understand this stuff.