0

我实际上尝试mysqli->fetch_array();获取数组但无法正常工作,所以我使用了 bind_result(); 它抛出以下错误

Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement

所以我对 bind_result 进行了错误检查,我得到的是bind_result() failed:我真正做错了什么?

$wtf = "";
$hello = "";
$check_empty_field = $mysqli - > prepare("select `username`, `firstname`, `lastname` from `vpb_uploads` where `username` = ?  and `firstname` = ? and `lastname` = ?");
$check_empty_field - > bind_param('sss', $username, $wtf, $hello);
$check_empty_field - > execute();
$check_empty_field - > store_result();
if($check_empty_field - > num_rows < 1) {
  $date = date("d-m-Y");
  $i2 = '';
  $i3 = '';
  $i4 = '';
  $i5 = '';
  $insert = $mysqli - > prepare("insert into `vpb_uploads` (`username`, `firstname`, `lastname`, image_one, image_two, image_three, image_four, image_five, date)values(?,?,?,?,?,?,?,?,?)");
  $insert - > bind_param('sssssssss', $username, $wtf, $hello, $random_name_generated, $i2, $i3, $i4, $i5, $date);
  $insert - > execute();
  $identity = "image_one";
} else {
  $get_empty_field = $check_empty_field - > bind_result($username, $wtf, $hello);
  if(false === $get_empty_field) {
    die('bind_result() failed: '.htmlspecialchars($mysqli - > error));
  }
  $image_one = strip_tags($get_empty_field["image_one"]);
  $image_two = strip_tags($get_empty_field["image_two"]);
  $image_three = strip_tags($get_empty_field["image_three"]);
  $image_four = strip_tags($get_empty_field["image_four"]);
  $image_five = strip_tags($get_empty_field["image_five"]);
  global $identity;
}
4

1 回答 1

0

抛出此错误是因为您尚未将 SQL 查询返回的每个列名设置为变量。

例子:

如果您的表格中有 6 列并且您选择了所有 (*),那么您将必须:

$stmt->bind_result($Col_1,$Col_2,$Col_3,$Col_4,$Col_5,$Col_6);

如果你有:

$stmt->bind_result($Col_1,$Col_2,$Col_3,$Col_4,$Col_5);

将抛出错误。


$check_empty_field->data_seek(0);
  $get_empty_field = $check_empty_field - > bind_result($username, $wtf, $hello);
于 2013-04-06T22:47:23.633 回答