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

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

      1. <tfoot id='kHGxs'></tfoot>
        <legend id='kHGxs'><style id='kHGxs'><dir id='kHGxs'><q id='kHGxs'></q></dir></style></legend>
      2. php 中的 get_result() 和 store_result() 有什么区别?

        时间:2023-07-30
      3. <tfoot id='DcFVx'></tfoot>

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

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

                <tbody id='DcFVx'></tbody>

                • <legend id='DcFVx'><style id='DcFVx'><dir id='DcFVx'><q id='DcFVx'></q></dir></style></legend>
                  本文介绍了php 中的 get_result() 和 store_result() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是我的代码.我正在检查登录/注册系统中是否存在用户:

                  This is my code. I am checking if a user exists or not in a login/registration system:

                  public function userExist($email){
                      $stmt = $this->conn->prepare("select email from users where email= ?");
                      $stmt->bind_param("s", $email);
                      $stmt->execute();
                      $stmt->store_result();
                      if($stmt->num_rows>0){
                  
                      }
                      else{
                  
                      }
                  }
                  

                  我可以使用 get_result 代替 store_result() 吗?

                  Can I use get_result instead of store_result() ?

                  推荐答案

                  这取决于您计划如何读取结果集.但是在您给出的实际示例中,您对读取任何返回的数据不感兴趣.您唯一感兴趣的是是否有记录.

                  It depends on how you plan to read the result set. But in the actual example you have given, you are not interested in reading any returned data. The only thing that interests you is whether there is a record or not.

                  在那种情况下,您的代码没问题,但它与 get_result 一起工作得同样好.

                  In that case your code is fine, but it would work equally well with get_result.

                  差异变得更加明显,例如,当您想要获取具有给定电子邮件的用户的 userid 时:

                  The difference becomes more apparent, when you want to get for example the userid of the user with the given email:

                  SELECT id FROM users WHERE email = ?
                  

                  如果你打算用 $stmt->fetch 读出 id,那么你会坚持store_result,并且会使用 bind_result 来定义你想在哪个变量中获得这个 id,就像这样:

                  If you plan to read out that id with $stmt->fetch, then you would stick to store_result, and would use bind_result to define in which variable you want to get this id, like this:

                  $stmt->store_result();    
                  $stmt->bind_result($userid);  // number of arguments must match columns in SELECT
                  if($stmt->num_rows > 0) {
                      while ($stmt->fetch()) {
                          echo $userid;  
                      }
                  }
                  

                  如果您希望获得一个结果对象,您可以在该对象上调用 fetch_assoc() 或任何 fetch_* 变体方法,那么您需要使用 get_result,例如这个:

                  If you prefer to get a result object on which you can call fetch_assoc() or any of the fetch_* variant methods, then you need to use get_result, like this:

                  $result = $stmt->get_result();   // You get a result object now
                  if($result->num_rows > 0) {     // Note: change to $result->...!
                      while ($data = $result->fetch_assoc()) {
                          echo $data['id'];
                      }
                  }
                  

                  请注意,您从 get_result 获取结果对象,而 store_result 则不是这种情况.您现在应该从结果对象中获取 num_rows.

                  Note that you get a result object from get_result, which is not the case with store_result. You should get num_rows from that result object now.

                  两种方式都可以,这真的是个人喜好问题.

                  Both ways work, and it is really a matter of personal preference.

                  这篇关于php 中的 get_result() 和 store_result() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 MySQLi 设置字符集 下一篇:仅使用 MySQLi 获取一行

                  相关文章

                  最新文章

                    1. <tfoot id='as6fz'></tfoot>
                        <bdo id='as6fz'></bdo><ul id='as6fz'></ul>
                      <legend id='as6fz'><style id='as6fz'><dir id='as6fz'><q id='as6fz'></q></dir></style></legend>

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

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