我实际上尝试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;
}
答案 0 :(得分: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);