What is a simple solution for dynamic mysqli bind_param arguments in PHP?

后端 未结 3 1220
一个人的身影
一个人的身影 2020-12-17 00:39

To build a bind_param dynamically, I have found this on other SO posts.

call_user_func_array(array(&$stmt, \'bindparams\'), $array_of_params);

3条回答
  •  无人及你
    2020-12-17 01:04

    array($stmt, 'bindparams') 
    

    is PHP's way of identifying method bind_params on the object $stmt, since PHP 5 you don't need to use the & in front any longer (and mysqli is PHP 5 so this looks like a glitch in the older post).

    you can see a similar example here

    so

    call_user_func_array(array($stmt, 'bindparams'), $array_of_params);
    

    basically means

    $stmt->bind_params($array_of_params[0], $array_of_params[1] ... $array_of_params[N])
    

提交回复
热议问题