What im trying to do is to create different insert statements in for loop and execute them while in loop. Is that possible?
Here's simplified code:
$mysqli = new mysqli("localhost", "user", "password", "database");
for($i=1; $i<10; $i++){
// $query string is created through code, so
// INSERT statement is varying after each loop.
// Lets say, in another step $query will be "INSERT INTO table (row4,row5) VALUES (?,?)";
// $params will be array("value4","value5");
$query = "INSERT INTO table (row1,row2,row3) VALUES (?,?,?)";
$param_type = "sss";
$params = array("value1","value2","value2");
$insert_stmt = $mysqli->prepare($query);
array_unshift($params, $param_type);
call_user_func_array(array($insert_stmt, 'bind_param'), refValues($params));
$insert_stmt->execute();
$insert_stmt->close();
}
What i get if i run this code is only one inserted row and warning "call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in..."
So my question is: how to prepare and insert different querys and parameters through for loop?