Reputation: 42997
I am pretty new in PHP and I have the following problem trying to define a simple query with parameter on an old PHP application. I have done in this way (mimic the other working query in this application that was made by someone else):
$result_facility_list = $db->prepare("select name from pm_facility where lang = :id_lang");
$result_hotel_file->bindParam(":id_lang", 2);
Then
The problem is that when it try to perform the second line that bind the integer value 2 to the :id_lang parameter I obtain this error message:
( ! ) Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\BeTrivius-Panda\templates\default\models\booking.php on line 534
Call Stack
# Time Memory Function Location
1 0.0326 165272 {main}( ) ..\index.php:0
2 8.2043 835656 include( 'C:\xampp\htdocs\BeTrivius-Panda\templates\default\models\booking.php' ) ..\index.php:146
What could be the problem? What am I missing? How can I fix this issue?
Upvotes: 0
Views: 45
Reputation: 2294
If you want to bind the int 2
to :id_lang
without it being a variable you can use bindValue()
:
$result_hotel_file->bindValue(":id_lang", 2, PDO::PARAM_INT);
if you want to use bindParam()
(as the name somewhat implies) you will have to use a variable:
$yourIdVar = 2;
$result_hotel_file->bindParam(":id_lang", $yourIdVar, PDO::PARAM_INT);
Upvotes: 1
Reputation: 4038
change this line
$result_hotel_file->bindParam(":id_lang", 2);
to
$id=2;
$result_hotel_file->bindParam(":id_lang", $id);
because you need to pass values to bindparam as variables
Upvotes: 2