<legend id='oqh3L'><style id='oqh3L'><dir id='oqh3L'><q id='oqh3L'></q></dir></style></legend>
<tfoot id='oqh3L'></tfoot>

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

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

      <bdo id='oqh3L'></bdo><ul id='oqh3L'></ul>

    1. 重置 PDO 中的光标位置

      时间:2023-09-19
        <i id='x5Om3'><tr id='x5Om3'><dt id='x5Om3'><q id='x5Om3'><span id='x5Om3'><b id='x5Om3'><form id='x5Om3'><ins id='x5Om3'></ins><ul id='x5Om3'></ul><sub id='x5Om3'></sub></form><legend id='x5Om3'></legend><bdo id='x5Om3'><pre id='x5Om3'><center id='x5Om3'></center></pre></bdo></b><th id='x5Om3'></th></span></q></dt></tr></i><div id='x5Om3'><tfoot id='x5Om3'></tfoot><dl id='x5Om3'><fieldset id='x5Om3'></fieldset></dl></div>
          <tbody id='x5Om3'></tbody>

            <bdo id='x5Om3'></bdo><ul id='x5Om3'></ul>
            <legend id='x5Om3'><style id='x5Om3'><dir id='x5Om3'><q id='x5Om3'></q></dir></style></legend>
              <tfoot id='x5Om3'></tfoot>
            • <small id='x5Om3'></small><noframes id='x5Om3'>

              • 本文介绍了重置 PDO 中的光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                $data=$stmt->fetchAll(); //Dumping the data shows the result. It is also setting the cursor at the end
                
                while($data=$stmt->fetch())
                {
                //Does not enters loop
                //If fetchAll() removes it work as usual
                }
                

                我知道它不需要两次获取数据.但我的主要问题是如何在 PDO 中重置光标位置?

                I know It dont need to fetch data twice. But my main question is How to reset cursor position in PDO?

                推荐答案

                AFAIK 无法使用 PDO 重置光标位置 - 这可能与某些不支持重置内部光标的数据库的兼容性有关.

                AFAIK there is no possibility to reset cursor position with PDO - that might something to do with compatibility with some databases, that don't support resetting internal cursors.

                如果你想对结果迭代两次,把它取到数组中并在这个数组上迭代:

                If you want to iterate twice over the results, fetch it to the array and iterate over this array:

                <?php 
                $results = $stmt->fetchAll();  
                foreach($results as $row) {
                    // first
                }
                
                foreach($results as $row) {
                    // second
                }
                

                编辑 某些数据库支持可滚动游标.要使用它,请将 PDO::CURSOR_SCROLL 标志添加到 prepare 方法(参见 PDOFetch 文档页面).但这只会增加向前或向后移动的可能性,而不是完全倒带.此外,并非所有数据库都支持这种类型的游标(例如 MySQL 不支持).

                Edit Some databases support scrollable cursors. To use that, add PDO::CURSOR_SCROLL flag to prepare method (see examples at PDOFetch documentation page). But that only adds possibility to move forward or backward, not rewind completely. Also, not all databases support that type of cursor (e.g. MySQL doesn't).

                这篇关于重置 PDO 中的光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Php PDO 功能有多安全:lastInsertId? 下一篇:PDO 语句转 JSON

                相关文章

                最新文章

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

                  <tfoot id='l1uPN'></tfoot>

                      <bdo id='l1uPN'></bdo><ul id='l1uPN'></ul>
                    <legend id='l1uPN'><style id='l1uPN'><dir id='l1uPN'><q id='l1uPN'></q></dir></style></legend>
                  1. <small id='l1uPN'></small><noframes id='l1uPN'>