The last example in that section shows a way of doing it with named placeholders, so I guess you could follow something along those lines if you wanted to use bindparam.
But the main point being made is that each value for the IN is an individual parameter itself, you can’t just bundle them all together in a single param. How you best achieve that is up to you.
$sql = "SELECT * FROM table WHERE id IN (??????????);
$stm = $db->prepare($sql);
$stm->execute(?????????)); // just would like to focus on bindparam for the IN operator
Would be interesting to see how you got it to work with that extra parentheses at the end there.
I thought the parametized execution has to be in an associative array for it to bind correctly? Or am I wrong? Unless that’s just the part you’re leaving out, but you’re using associative arrays.
if I understand the context, not necessarily. I prefer named placeholders myself so I could be wrong, but AFAIK if not using named placeholders the order has to be exact.
For example, I may now know that “?,?,?” is for “id, name, date” but will I later? If I have “:id, :name, :date” I won’t need to rely on my memory and risk making a mistake by feeding it “id, date, name”
The second one fails because you are wrapping the associative array’s variable inside another array. Arrays require a string to be passed as an argument. However, since you are wrapping an array within a array, you will get the array to string conversion error since arrays can’t be turned into strings that way. I know you aren’t trying to do that so don’t wrap an array within an array if the variable already contains an array.
Ah. That is quite interesting. I prefer parametized placeholders because you know what you are binding. It is also good practice to understand what you are binding.