I explain myself…
I have a form with fill the query (eg.):
SELECT *
FROM table
WHERE id=? AND name=? AND sex=? AND year=? AND class=?
but only the “id” is mandatory, all the other parameter are optional.
How can I fill (or re-create) the prerared statement for that query ???
You’d either have to use multiple prepared statements or just create a statement on the fly, checking which parameters you have.
Like this:
Update/Warning: Don’t directly add the parameter values to the query string but use
PreparedStatementand the like instead. As displayed above the query string should only contain placeholders for the values (eg.?) in order to prevent SQL-injection attacks.What I mean is, do NOT do the following: