You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we're going to make Statement objects reusable, that means they need to be able to have parameters rebound (which is currently possible).
$stmt = $db->prepare("SELECT * FROM tblTest WHERE intKey1 = ? AND intKey2 = ?");
$stmt->fetchAll(null, [65, 595]); // bind 65 to intKey1 and 595 to intKey2$stmt->fetchAll(null, [123,123]); // use the statement again with new params \o/
But, what happens if someone calls:
$stmt->fetchAll(null, [321]); // intKey2 is still set to 123 from the previous bind, silly programmer
We have a few improvements:
in fetchOne and fetchAll, the array supplied must cover the full number of parameters
have a resetParams() method and encourage this before rebinding
calling "bind" on the same parameter twice (i.e. the very first time, execute, then bind again for the subsequent call) sets the class into an internal state which says "if they don't bind all the parameters before the next execute, throw an exception".
I'll be honest and say that the third feels like hidden behaviour. 1 and 2 probably cover us off. We have to consider that a programmer may want to re-use parameters from a previous execution, so even enforcing 1 might be cumbersome.
The text was updated successfully, but these errors were encountered:
If we're going to make
Statement
objects reusable, that means they need to be able to have parameters rebound (which is currently possible).But, what happens if someone calls:
We have a few improvements:
fetchOne
andfetchAll
, the array supplied must cover the full number of parametersI'll be honest and say that the third feels like hidden behaviour. 1 and 2 probably cover us off. We have to consider that a programmer may want to re-use parameters from a previous execution, so even enforcing 1 might be cumbersome.
The text was updated successfully, but these errors were encountered: