I am new to PHP and I'm trying to make a function that can insert any arguments given in the param into a table specified also as a param of the function, but when I execute my code it says:
call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
here is my code:
function insert($table, $args){
$Query = "INSERT INTO ? VALUES(";
$types="";
foreach($args as $arg){
$Query=$Query."?,";
$type = gettype($arg);
switch ($type) {
case "string":
$types = $types."s";
break;
case "integer":
case "double":
$types = $types."d";
break;
}
}
$Query=substr($Query, 0, -1);
$Query=$Query.")";
global $mysqli;
$stmt=$mysqli->prepare($Query);
echo $stmt;
array_unshift($args, $table);
array_unshift($args, $types);
call_user_func_array(array($stmt, "bind_param"), $args);
$stmt->execute();
}
so what's wrong here and thank you?