<legend id='9QZLY'><style id='9QZLY'><dir id='9QZLY'><q id='9QZLY'></q></dir></style></legend>

      <i id='9QZLY'><tr id='9QZLY'><dt id='9QZLY'><q id='9QZLY'><span id='9QZLY'><b id='9QZLY'><form id='9QZLY'><ins id='9QZLY'></ins><ul id='9QZLY'></ul><sub id='9QZLY'></sub></form><legend id='9QZLY'></legend><bdo id='9QZLY'><pre id='9QZLY'><center id='9QZLY'></center></pre></bdo></b><th id='9QZLY'></th></span></q></dt></tr></i><div id='9QZLY'><tfoot id='9QZLY'></tfoot><dl id='9QZLY'><fieldset id='9QZLY'></fieldset></dl></div>

      <small id='9QZLY'></small><noframes id='9QZLY'>

      1. <tfoot id='9QZLY'></tfoot>
          <bdo id='9QZLY'></bdo><ul id='9QZLY'></ul>
      2. 警告:mysqli_stmt::bind_result():绑定变量的数量与准备

        时间:2023-07-30
        <i id='YbYiI'><tr id='YbYiI'><dt id='YbYiI'><q id='YbYiI'><span id='YbYiI'><b id='YbYiI'><form id='YbYiI'><ins id='YbYiI'></ins><ul id='YbYiI'></ul><sub id='YbYiI'></sub></form><legend id='YbYiI'></legend><bdo id='YbYiI'><pre id='YbYiI'><center id='YbYiI'></center></pre></bdo></b><th id='YbYiI'></th></span></q></dt></tr></i><div id='YbYiI'><tfoot id='YbYiI'></tfoot><dl id='YbYiI'><fieldset id='YbYiI'></fieldset></dl></div>
        <legend id='YbYiI'><style id='YbYiI'><dir id='YbYiI'><q id='YbYiI'></q></dir></style></legend>
          <tbody id='YbYiI'></tbody>
          <bdo id='YbYiI'></bdo><ul id='YbYiI'></ul>

          <small id='YbYiI'></small><noframes id='YbYiI'>

            <tfoot id='YbYiI'></tfoot>

                  本文介绍了警告:mysqli_stmt::bind_result():绑定变量的数量与准备好的语句错误中的字段数量不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 mysql 查询,我正在将其转换为 mysqli(准备好的语句),但遇到了一个问题,引发了以下错误,

                  I had a mysql query and I was converting it to mysqli(prepared statement) but I ran in to a problem which throws the below error,

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

                  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);

                  The below is what I tried even though it didn't work. I already knew it won't work but I wanted to try it myself before asking a question. And the error is coming from the $get_empty_field = $stmt->bind_result($stmt);

                  if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) {
                      $firstname = '""';
                      $lastname = '""';
                      $stmt = $mysqli->prepare("select * from `vpb_uploads` where `username` = ?  and `firstname` = ? and `lastname` = ?");
                      $stmt->bind_param('sss', $username, $firstname, $lastname);
                      $stmt->execute();
                      $stmt->store_result();
                      if ($stmt->num_rows < 1) {
                          $date = 'date("d-m-Y")';
                          $image_2 = "''";
                          $image_3 = "''";
                          $image_4 = "''";
                          $image_5 = "''";
                          $stmt = $mysqli->prepare("insert into `vpb_uploads` (`username`, `firstname`, `lastname`, `image_one`, `image_two`, `image_three`, `image_four`, `image_five`, `date`) values(?,?,?,?,?,?,?,?,?)");
                          $stmt->bind_param('sssssssss', $username, $firstname, $lastname, $random_name_generated, $image_2, $image_3, $image_4, $image_5, $date);
                          $stmt->execute();
                          $stmt->close();
                  
                          $identity = "image_one";
                      } else {
                          $get_empty_field = $stmt->bind_result($stmt);
                          $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);
                  

                  $get_empty_field = $stmt->bind_result($field1, $field2, $field3);
                  

                  $fieldx 变量的数量等于所选字段的数量.如果你不知道有多少,使用这个:

                  The number of $fieldx variables being equal to the number of fields that are selected. If you don't know how many there are, use this:

                    // 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'];

                  And then you access the result, after fetching, with $data['field'];

                  这篇关于警告:mysqli_stmt::bind_result():绑定变量的数量与准备好的语句错误中的字段数量不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何创建动态 WHERE 子句 下一篇:如何使用 mysqli 编写一个安全的 SELECT 查询,该查

                  相关文章

                  最新文章

                  <i id='iZxhr'><tr id='iZxhr'><dt id='iZxhr'><q id='iZxhr'><span id='iZxhr'><b id='iZxhr'><form id='iZxhr'><ins id='iZxhr'></ins><ul id='iZxhr'></ul><sub id='iZxhr'></sub></form><legend id='iZxhr'></legend><bdo id='iZxhr'><pre id='iZxhr'><center id='iZxhr'></center></pre></bdo></b><th id='iZxhr'></th></span></q></dt></tr></i><div id='iZxhr'><tfoot id='iZxhr'></tfoot><dl id='iZxhr'><fieldset id='iZxhr'></fieldset></dl></div>

                1. <small id='iZxhr'></small><noframes id='iZxhr'>

                2. <tfoot id='iZxhr'></tfoot>

                      <bdo id='iZxhr'></bdo><ul id='iZxhr'></ul>
                    <legend id='iZxhr'><style id='iZxhr'><dir id='iZxhr'><q id='iZxhr'></q></dir></style></legend>