2
$type = array('i','i');
$param = array("1","1");
$stmt = $mysqli->prepare("SELECT par1, par2 FROM table WHERE par3 = ? AND par4 = ?");
$refs = array();
foreach($param as $key => $value) {
        $refs[$key] = &$param[$key];
}
$result_params = array_merge($type,$refs);
call_user_func_array(array($stmt, 'bind_param'), $result_params);
$stmt->execute();

var_dump($result_params):

array(4) {
  [0]=>
  string(1) "i"
  [1]=>
  string(1) "i"
  [2]=>
  &string(1) "1"
  [3]=>
  &string(1) "1"
}

When we use code we are get error:

Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in ...

Why we are get this error an how to fix the problem ?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Nik
  • 121
  • 10
  • Does this answer your question? [mysqli bind\_param() expected to be a reference, value given](https://stackoverflow.com/questions/16120822/mysqli-bind-param-expected-to-be-a-reference-value-given) – Dharman Mar 15 '22 at 17:30

1 Answers1

2

Problem solved.

Resolve the issue:

instead $type = array('i','i'); need use $type = array('ii');

Nik
  • 121
  • 10