18

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);
chustar
  • 12,225
  • 24
  • 81
  • 119
  • 8
    Why 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. – Marc B Apr 06 '11 at 16:40

2 Answers2

33

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
N.B.
  • 13,688
  • 3
  • 45
  • 55
  • Note that the first string is not a parameter, those are the **Type specification chars**, see http://php.net/manual/en/mysqli-stmt.bind-param.php – jeroen Apr 06 '11 at 16:50
  • Yes, 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. – N.B. Apr 06 '11 at 16:54
0

Check $config_name argument. '1' not pass as refernces

Andrew
  • 13,757
  • 13
  • 66
  • 84
saint
  • 3,787
  • 5
  • 19
  • 17