0

I am having trouble with calling bind_param via call_user_func_array. I am trying to do it like this:

call_user_func_array(array($stmt, "bind_param"), array_merge(array($types), $params));

and I am getting this error:

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

I thought it was because my array was malformed as other questions have noted but I did a var dump like this:

var_dump(array_merge(array($types), $params));

and I got this result, which I thought was the correct input format:

array (size=2)
  0 => string 's' (length=1)
  1 => string 'Hello' (length=5)

Please could somebody tell me where the error lies?

u_mulder
  • 54,101
  • 5
  • 48
  • 64
kabeersvohra
  • 1,049
  • 1
  • 14
  • 31
  • Possible duplicate of [Bind multiple parameters into mysqli query](http://stackoverflow.com/questions/17870999/bind-multiple-parameters-into-mysqli-query) – u_mulder Sep 17 '16 at 20:53
  • Btw it is not `pdo` you're using, it's `mysqli` – u_mulder Sep 17 '16 at 20:54
  • @u_mulder please read my question before voting as a duplicate, I saw this specific question when trying to find a solution myself and it did not solve the problem as they mentioned that the input array was wrong whereas mine is correct as I demonstrated with a var_dump – kabeersvohra Sep 17 '16 at 21:12
  • The solution for your question is line `$bind[$key] = &$values[$key];` So, your `$params` array must store not values but references. That's all. – u_mulder Sep 18 '16 at 07:47

0 Answers0