Using PDOStatement::bindParam()
, one can bind a parameter to a variable—which is especially useful when a prepared statement is executed multiple times, each with different parameter values. For example:
$dbh = new PDO('mysql:dbname=foo', 'eggyal', 'password1');
$qry = $dbh->prepare('DELETE FROM bar WHERE qux = ?');
$qry->bindParam(1, $qux, PDO::PARAM_INT);
while (true) {
$qux = ... ;
$qry->execute();
// etc
}
My questions are:
-
Is it possible to bind a parameter to the member variable of an object? For example:
$qry->bindParam(1, $obj->qux, PDO::PARAM_INT);
-
If so, to which object's member variable is such a parameter bound: that which is referenced at the time of the
bindParam()
call, or that which is referenced upon statement execution? For example:$obj->qux = 123; $obj = new stdClass(); $obj->qux = 456; $qry->execute(); // which value is used for qux ?
Where is this behaviour documented (if at all)?