I'm trying to write a little wrapper for executing MySQL statements, and I've run into a wall trying to use mysqli_bind_param
without knowing the number of variables I'm binding. Here's what I've got:
/**
* Note:
* . execSQL is variadic, just like bind_param
* . prepareTypeStr is another custom function that generates
* the type string `mysqli_bind_param` requires through variadic
* parameters as well
*/
private function execSQL( $prepStmt ) {
$variables = func_get_args();
array_shift( $variables ); // first arg is prepStmt, not a variable
$query = $this->db->prepare( $prepStmt );
if( $query ) {
/**
* here's the problem: I've now got an array full of the
* variables passed to execSQL, but bind_param only
* accepts multiple parameters.
*/
$query->bind_param(
prepareTypeStr( /* variable1, variable2, ... */ ),
/* variable1, variable2, ... */ );
// ... rest of the function ...
}
}
Any ideas?