Here's how bindParam
is intended to be used:
$this->array = $array; //Array ( [0] => alpha [1] => bravo [2] => charlie )
$query = "INSERT INTO test SET Name = :Name";
$sql = $this->conn->prepare($query);
$sql->bindParam(":Name" , $value , PDO::PARAM_STR);
foreach($this->array as $value) {
$sql->execute();
}
That is, you bind the named parameter to one of your variables so every time you execute the query the named parameter will obtain its value from the current variable value.
By contrast, if you use bindValue
you need to re-bind each time you need to change the named parameter value:
$query = "INSERT INTO test SET Name = :Name";
$sql = $this->conn->prepare($query);
foreach($this->array as $v) {
$sql->bindValue(":Name" , $v , PDO::PARAM_STR);
$sql->execute();
}
The advantage of bindParam
is that there's less allocations and passing around going on.