Php 警告:mysqli_stmt::bind_result():绑定变量的数量不';与准备语句中的字段数不匹配错误

Php 警告:mysqli_stmt::bind_result():绑定变量的数量不';与准备语句中的字段数不匹配错误,php,Php,我有一个mysql查询,我正在将其转换为mysqli(prepared语句),但我遇到了一个问题,抛出了以下错误 Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement Mysql代码 $random_name_generated = vpb_generate_random_name().'.jpg'; //Generat

我有一个mysql查询,我正在将其转换为mysqli(prepared语句),但我遇到了一个问题,抛出了以下错误

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

$random_name_generated = vpb_generate_random_name().'.jpg'; //Generated name for uploaded files or images

                    if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) 
                    {
                    $check_empty_field = mysql_query("select * from `vpb_uploads` where `username` = '".mysql_real_escape_string(strip_tags($username))."'  and `firstname` = '".mysql_real_escape_string("")."' and `lastname` = '".mysql_real_escape_string("")."'");
                    if(mysql_num_rows($check_empty_field) < 1)
                    {
                    mysql_query("insert into `vpb_uploads` values('', '".mysql_real_escape_string($username)."', '', '', '".mysql_real_escape_string($random_name_generated)."', '', '', '', '', '".mysql_real_escape_string(date("d-m-Y"))."')");

                    $identity = "image_one";
                    }
                    else
                    {
                    $get_empty_field = mysql_fetch_array($check_empty_field);
                    $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;
你需要改变

$get_empty_field = $stmt->bind_result($stmt);

$fieldx
变量的数量等于所选字段的数量。如果您不知道有多少,请使用以下命令:

  // Throw an exception if the result metadata cannot be retrieved
  if (!$meta = $stmt->result_metadata())
  {
    throw new Exception($stmt->error);
  }

  // The data array
  $data = array();

  // The references array
  $refs = array();

  // Iterate over the fields and set a reference
  while ($name = $meta->fetch_field())
  {
    $refs[] =& $data[$name->name];
  }

  // Free the metadata result
  $meta->free_result();

  // Throw an exception if the result cannot be bound
  if (!call_user_func_array(array($stmt, 'bind_result'), $refs))
  {
    throw new Exception($stmt->error);
  }

然后在获取后,使用
$data['field']
访问结果

我改变了你说的,但它仍然抛出警告。表中有多少字段?您向
bind\u result
函数传递了多少个变量?表中有9个字段,我传递了3个变量。我确实进行了编辑以修复示例中的错误,因此您可能希望再次复制我的代码。另外,如果有10个字段,那么您需要传递10个变量(当使用
SELECT*
时)。哦,我不知道如何修复它,您能告诉我如何使它显示错误吗?我的意思是像mysqli->error()这样的东西;如果这是一个mysqli错误。
$get_empty_field = $stmt->bind_result($field1, $field2, $field3);
  // Throw an exception if the result metadata cannot be retrieved
  if (!$meta = $stmt->result_metadata())
  {
    throw new Exception($stmt->error);
  }

  // The data array
  $data = array();

  // The references array
  $refs = array();

  // Iterate over the fields and set a reference
  while ($name = $meta->fetch_field())
  {
    $refs[] =& $data[$name->name];
  }

  // Free the metadata result
  $meta->free_result();

  // Throw an exception if the result cannot be bound
  if (!call_user_func_array(array($stmt, 'bind_result'), $refs))
  {
    throw new Exception($stmt->error);
  }