Re: How do you dynamically add additional variables to a PDO SQL query?
> A 'compute engine'?
Read again. A query edit or Query By Example module which combines a query shell with a user's runtime input into valid sql.
> Sorry to sound funny, but this seems so overly complicated for what we need.
If the solution's as simple as you suggest, would you need to ask how to do it?
> We just need to compile the variables somehow.
> Then if a variable is populated, add that to the query dynamically.
"Compile the variables" requires parsing variables and their values into valid sql.
If there's just one table that users may query, and if there are just a couple of columns that a user may canvass in her query, you can write specific code to parse each user variable into a subclause to replace an existing Where subclause or to be added to the Where clause. That gives users a small set of limited queries for one table.
But an ironclad rule of app development is that either the app will die or its requirement will grow and change. When the table structure changes, you will need to rewrite your module. When users need such query flexibility for another table, you'll need to write another module for that table and its columns. And so on. Your simplicity will be an albatross.
The meaning and number of possible user query variables for even a relatively simple set of tables is in practical terms unlimited, which is why the developer is better off with a generalised query edit or QBE module.
It's one of the reasons many PHP developers use frameworks---the good ones provide such logic, though then you're stuck with their assumptions and APIs.