This is my function which creates the prepared statement:
function query($query, $values_array) {
if ($stmt = $link->prepare($query)) {
for ($i = 1; $i < count($values_array); $i++) {
if (!$stmt->bind_param($values_array[0][$i-1], $values_array[$i])) {
return false;
}
}
if (!$stmt->execute()) {
return false;
}
$result = $stmt->get_result();
$stmt->close();
}
return $result;
}
$query is
insert into table (var1, var2, var3, var4, var5, var6) values (?, ?, ?, ?, ?, ?)
$values_array is
array(7) {
[0]=>
string(6) "diisii"
[1]=>
float(9)
[2]=>
int(1)
[3]=>
int(1)
[4]=>
string(5) "now()"
[5]=>
int(1)
[6]=>
int(1)
}
I cannot figure out the problem as this error is only thrown when binding params to an insert statement. Select statements work without problems!
now()wouldn't work, as it was passed as literal string. And you could try using the alternative->bind_paramsignature of passing the type string together with all params,call_user_func_array(array($stmt, "bind_param"), $values_array)