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 に答える