Skip to content
Advertisement

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

I’m using this code and I’m beyond frustration:

JavaScript

PDO::PARAM_NULL, null, '', all of them fail and throw this error:

Fatal error: Cannot pass parameter 2 by reference in /opt/…

Advertisement

Answer

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:

JavaScript

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.)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement