0

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

doovers
  • 8,545
  • 10
  • 42
  • 70
  • 2
    `bind_param` requires variable references, not values. `$data` doesn't contain references. – Barmar Oct 18 '13 at 02:59
  • 1
    If you're using PHP 5.3+, you may consider the recommendation in [this comment](http://www.php.net/manual/en/mysqli-stmt.bind-param.php#104073). – Passerby Oct 18 '13 at 03:04
  • @Barmar Thanks for the response. I had tried to convert to references using the refValues function on php.net but I must have had done something wrong because I just tried again to double check and it worked this time around. Sorry for wasting your time I've been trying to figure this out for an hour already!! – doovers Oct 18 '13 at 03:08
  • @Barmar If you want to add your answer I can mark the question answered. – doovers Oct 18 '13 at 03:10
  • 2
    I already marked it as a duplicate, I think that's sufficient. – Barmar Oct 18 '13 at 03:10

0 Answers0