I'm trying to pass an array of values to bind_param but I'm getting an error when I execute the statement! What am I doing wrong?
Error:
Execute failed: (2031) No data supplied for parameters in prepared statement
Code:
$mysqli = new mysqli($this->host, $this->user, $this->pass, $this->db) ;
if ($mysqli->connect_errno) {
$this->err_state = "Connect failed: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
return false;
}
$field_string = implode(",", $this->sql_object->field_array);
$table = $this->sql_object->table;
$prep_string = $this->create_prep_string($this->sql_object->value_array);
$this->sql = "INSERT INTO $table ($field_string) VALUES ($prep_string)";
if (!($stmt = $mysqli->prepare($this->sql))) {
$this->err_state = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
return false;
}
$type_string = $this->create_type_string($this->sql_object->value_array);
$data = array_merge(array($type_string), $this->sql_object->value_array);
call_user_func_array(array($stmt, 'bind_param'), $data);
$this->message = $data;
if (!$stmt->execute()) {
$this->err_state = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
$stmt->close();
return false;
}
$mysqli->close();
return true;
The output of the $data
variable is:
array(4) { [0]=> string(3) "iss" [1]=> int(1) [2]=> string(1) "A" [3]=> string(1) "B" }
EDIT:
For the benefit of anyone else who reads this, I solved the problem this function: http://php.net/manual/en/mysqli-stmt.bind-param.php#96770