What is a simple solution for dynamic mysqli bind_param arguments in PHP?
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])
As far as I know, you cannot pass the result of e.g.
$userid == "ALL"
to a mysqli-statement-Object's bind_param method, because this method wants the parameters to be passed by reference. Obviously this is not possible with the result of an expression evaluated "in place".
As a workaround, I changed the program's second part to
$userIdEmpty = $userid == "ALL";
$locationEmpty = $location = "ALL";
$stmt->bind_param( "siiiii",
"active", $userid, $userIdEmpty,
$location, $locationEmpty,
$limit);
Like that, the result of the boolean operation can be passed by reference.