• <tfoot id='Gh0iD'></tfoot>

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

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

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

        • <bdo id='Gh0iD'></bdo><ul id='Gh0iD'></ul>

        PDO 循环通过并打印 fetchAll

        时间:2023-10-05

          <tfoot id='f08aT'></tfoot>

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

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

                  <bdo id='f08aT'></bdo><ul id='f08aT'></ul>
                  本文介绍了PDO 循环通过并打印 fetchAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我无法从 fetchAll 获取数据以进行选择性打印.

                  I'm having trouble getting my data from fetchAll to print selectively.

                  在普通的 mysql 中,我是这样做的:

                  In normal mysql I do it this way:

                  $rs = mysql_query($sql);
                  while ($row = mysql_fetch_array($rs)){
                     $id = $row['id'];
                     $n = $row['n'];
                     $k = $row['k'];
                  }
                  

                  在 PDO 中,我遇到了麻烦.我绑定了参数,然后像上面一样将获取的数据保存到 $rs 中,目的是以相同的方式循环遍历它..

                  In PDO, I'm having trouble. I bound the params, then I'm saving the fetched data into $rs like above, with the purpose of looping through it the same way..

                  $sth->execute();
                  $rs = $query->fetchAll();
                  

                  现在是麻烦的部分.我该怎么做 PDO-wise 才能得到与上面的 while 循环匹配的东西?!我知道我可以使用 print_r() 或 dump_var,但这不是我想要的.我需要做我以前可以用常规 mysql 做的事情,比如根据需要单独抓取 $id、$n、$k.可能吗?

                  Now comes the trouble part. What do I do PDO-wise to get something matching the while loop above?! I know I can use print_r() or dump_var, but that's not what I want. I need to do what I used to be able to do with regular mysql, like grabbing $id, $n, $k individually as needed. Is it possible?

                  提前致谢..

                  推荐答案

                  应该是

                  while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                    $id = $row['id'];
                    $n = $row['n'];
                    $k = $row['k'];
                  }
                  

                  如果你坚持fetchAll,那么

                  $results = $query->fetchAll(PDO::FETCH_ASSOC);
                  foreach($results as $row) {
                     $id = $row['id'];
                     $n = $row['n'];
                     $k = $row['k'];
                  }
                  

                  PDO::FETCH_ASSOC 仅获取列名并省略数字索引.

                  PDO::FETCH_ASSOC fetches only column names and omits the numeric index.

                  这篇关于PDO 循环通过并打印 fetchAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:大结果集的 PDO/MySQL 内存消耗 下一篇:PDO 和 MariaDB

                  相关文章

                  最新文章

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

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

                        <bdo id='FByeQ'></bdo><ul id='FByeQ'></ul>
                    1. <small id='FByeQ'></small><noframes id='FByeQ'>

                      <tfoot id='FByeQ'></tfoot>