Cannot pass parameter by reference in MySQLi
16,519
'1' cannot be passed by reference because it's not a variable but a literal. You need to create a variable with mentioned value and bind it instead because bind_param()
function expects variables passed by reference.
Related videos on Youtube
Author by
chustar
I just hit 1500 reputation! - Wait, no I didn't... - Haha, yes I did!
Updated on March 08, 2021Comments
-
chustar about 3 years
I am trying to pass a string into my MySQLi prepared statement but it gives me the error:
Cannot pass parameter by reference in MySQLi
Here is the relevant code:
$kv = json_encode(array($key => $value)); $stmt->prepare("insert into rules (application_id, ruletype, rule_name, rule_info) values (?, ?, ?, ?);"); $stmt->bind_param('iiss', $application_id, 1, $config_name, $kv);
-
Marc B about 13 yearsWhy not simply embed the
'1'
directly into the query? If it's a static value, there's no point in making it a bound parameter. Otherwise, simply do$one = 1;
and then pass in$one
into the bind call. You can't make a reference to a constant.
-
-
jeroen about 13 yearsNote that the first string is not a parameter, those are the Type specification chars, see php.net/manual/en/mysqli-stmt.bind-param.php
-
N.B. about 13 yearsYes, you're right, my bad - I skimmed trough the question and noticed that OP isn't passing an argument as variable. I'll edit the answer with your input.