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

      2. <small id='BSaRU'></small><noframes id='BSaRU'>

      3. 如何在 php 中使用 bind_result() 而不是 get_result()

        时间:2023-07-29
        <legend id='qOBrw'><style id='qOBrw'><dir id='qOBrw'><q id='qOBrw'></q></dir></style></legend>

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

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

                    <tbody id='qOBrw'></tbody>

                  本文介绍了如何在 php 中使用 bind_result() 而不是 get_result()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在为 uni 开发一个项目,并且一直在 testing server 上使用以下代码从基于 的表中获取所有设备user_id:

                  I'm working on a project for uni and have been using the following code on a testing server to get all devices from a table based on a user_id:

                  public function getAllDevices($user_id) {
                      $stmt = $this->conn->prepare("SELECT * FROM devices WHERE  primary_owner_id = ?");
                      $stmt->bind_param("i", $user_id);
                      $stmt->execute();
                      $devices = $stmt->get_result();
                      $stmt->close();
                      return $devices;
                  }
                  

                  这在我的测试服务器上运行良好,但在迁移到大学项目服务器时返回此错误:

                  This worked fine on my testing server but returns this error when migrating over to the university project server:

                  Call to undefined method mysqli_stmt::get_result()
                  

                  一些谷歌搜索建议使用 bind_result() 而不是 get_result() 但我不知道如何在表中执行此all fields.大多数示例只显示返回 one field

                  Some googling suggests using bind_result() instead of get_result() but I have no idea how to do this all fields in the table. Most examples only show returning one field

                  任何帮助将不胜感激

                  推荐答案

                  假设你不能使用 get_result() 并且你想要一个设备数组,你可以这样做:

                  Assuming you can't use get_result() and you want an array of devices, you could do:

                  public function getAllDevices($user_id) {
                      $stmt = $this->conn->prepare("SELECT device_id, device_name, device_info FROM devices WHERE  primary_owner_id = ?");
                      $stmt->bind_param("i", $user_id);
                      $stmt->execute();
                      $stmt->bind_result($id, $name, $info);
                      $devices = array();
                  
                      while($stmt->fetch()) {
                          $tmp = array();
                          $tmp["id"] = $id;
                          $tmp["name"] = $name;
                          $tmp["info"] = $info;
                          array_push($devices, $tmp);
                      }
                      $stmt->close();
                      return $devices;
                  }
                  

                  这会创建一个临时数组并存储其中每一行的数据,然后将其推送到主数组.据我所知,您不能在 bind_result() 中使用 SELECT *.相反,您将不得不在 SELECT

                  This creates a temporary array and stores the data from each row in it, and then pushes it to the main array. As far as I'm aware, you can't use SELECT * in bind_result(). Instead, you will annoyingly have to type out all the fields you want after SELECT

                  这篇关于如何在 php 中使用 bind_result() 而不是 get_result()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP mysqli_fetch_field 数据类型 下一篇:php mysql SET NAMES 'utf8' COLLATE 'utf8_unicode_

                  相关文章

                  最新文章

                    <bdo id='UHbo9'></bdo><ul id='UHbo9'></ul>
                • <tfoot id='UHbo9'></tfoot>

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

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

                      <legend id='UHbo9'><style id='UHbo9'><dir id='UHbo9'><q id='UHbo9'></q></dir></style></legend>