Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot pass parameter 2 by reference error in php PDO

Tags:

php

pdo

I am getting the error: Cannot pass parameter 2 by reference in.....

in this line...

$stmt1->bindParam(':value', $_SESSION['quantity'.$i] * $_SESSION['price'.$i], PDO::PARAM_STR);   

What is wrong with code above ??

like image 641
user3790186 Avatar asked Mar 24 '26 19:03

user3790186


1 Answers

I'd say it's the typical confusion between PDO:bindParam() and what you probably intended to use: PDO:bindValue().

PDOStatement::bindParam

Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement. Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

PDOStatement::bindValue

Binds a value to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement.

like image 196
Álvaro González Avatar answered Mar 27 '26 08:03

Álvaro González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!