I have function in PHP, which should bind in MySQL IN statement so many variables, that is in array. My problem is that variable and key is changing but function bind only last
There is the difference between PDO::bindParam() and PDO::bindValue(). PDO::bindParam
binds reference, not value. When foreach process ends, $param
will reference to the last array value. In the time of execute
call all binded references will be evaluated to same value.
Official PDO::bindParam
documentation says:
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.
If you want bind values in foreach
use PDO::bindValue
.