2

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!

Chris
  • 1,316
  • 2
  • 13
  • 20
  • The `now()` wouldn't work, as it was passed as literal string. And you could try using the alternative `->bind_param` signature of passing the type string together with all params, `call_user_func_array(array($stmt, "bind_param"), $values_array)` – mario Feb 23 '13 at 16:16
  • Same error when leaving the now() out. Yes, I know the call_user_func_array function however I needed to restructure the $values_array which I don't want to do. – Chris Feb 23 '13 at 16:25

0 Answers0