0

我正在尝试将一组值传递给 bind_param 但在执行语句时出现错误!我究竟做错了什么?

错误:

执行失败:(2031)没有为准备好的语句中的参数提供数据

代码:

$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;

$data变量的输出是:

array(4) { [0]=> string(3) "iss" [1]=> int(1) [2]=> string(1) "A" [3]=> string(1) "B" }

编辑:

为了其他阅读本文的人的利益,我解决了这个函数的问题:http: //php.net/manual/en/mysqli-stmt.bind-param.php#96770

4

0 回答 0