Php mysqli bind_param与数组

时间:2013-10-18 02:53:21

标签: php mysqli prepared-statement

我正在尝试将一个值数组传递给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

0 个答案:

没有答案