PHP Fatal error: Cannot pass parameter 2 by reference


PHP


Asked on December 28, 2022
I have a PHP code to save data in MySQL. I am using PDO connection.

$Stmt = $con->prepare($query);
$Stmt->bindParam(1,101,PDO::PARAM_INT,10);
$Stmt->bindParam(2,'Hello World!',PDO::PARAM_STR,300);
$Stmt->execute();

When I run the code, getting exception as

PHP Fatal error:  Cannot pass parameter 2 by reference




Replied on December 28, 2022
Use variable to pass values.

$id = 101;
$vid = 'Hello World!';

$Stmt = $con->prepare($query);
$Stmt->bindParam(1,$id,PDO::PARAM_INT,10);
$Stmt->bindParam(2,$vid,PDO::PARAM_STR,300);
$Stmt->execute();



Replied on December 28, 2022
Thanks, working.


Write Answer









©2024 concretepage.com | Privacy Policy | Contact Us