Brecht Valcke Brecht Valcke - 1 year ago 90
PHP Question

Passing an Array as Arguments in php

I'm trying to prepare a sql statement with unknown amount of parameters! These parameters are past on in an array. The normal syntax for the function would be:

$stmt->bind_param("string of types",param1,param2,...,paramN)

The problem is I dont know how to add parameters in the function $stmt->bind_param out of an array

I have this code but it does not work:

$stmt= $conn->prepare($request['query']);
$result = $stmt->get_result();

$request['params'] contains the right parameters that need to be added in the function.

But the call_user_func_array gives me this error:

call_user_func_array() expects parameter 1 to be a valid callback, function '$stmt->bind_param' not found or invalid function.

I think call_user_func_array might not be the right function to use!
I googled for hours but could not find a solution for this small problem.

Answer Source

Try something like:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download