Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?

You need to use bindValue, not bindParam

bindParam takes a variable by reference, and doesn’t pull in a value at the time of calling bindParam. I found this in a comment on the PHP docs:

bindValue(':param', null, PDO::PARAM_INT);

P.S. You may be tempted to do this bindValue(':param', null, PDO::PARAM_NULL); but it did not work for everybody (thank you Will Shaver for reporting.)

Leave a Comment