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

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

      <i id='qQANx'><tr id='qQANx'><dt id='qQANx'><q id='qQANx'><span id='qQANx'><b id='qQANx'><form id='qQANx'><ins id='qQANx'></ins><ul id='qQANx'></ul><sub id='qQANx'></sub></form><legend id='qQANx'></legend><bdo id='qQANx'><pre id='qQANx'><center id='qQANx'></center></pre></bdo></b><th id='qQANx'></th></span></q></dt></tr></i><div id='qQANx'><tfoot id='qQANx'></tfoot><dl id='qQANx'><fieldset id='qQANx'></fieldset></dl></div>
      <tfoot id='qQANx'></tfoot>
      <legend id='qQANx'><style id='qQANx'><dir id='qQANx'><q id='qQANx'></q></dir></style></legend>
      1. 相当于 mysql_num_rows 或 mssql_num_rows 的 PDO

        时间:2023-10-05
        <i id='LsxIA'><tr id='LsxIA'><dt id='LsxIA'><q id='LsxIA'><span id='LsxIA'><b id='LsxIA'><form id='LsxIA'><ins id='LsxIA'></ins><ul id='LsxIA'></ul><sub id='LsxIA'></sub></form><legend id='LsxIA'></legend><bdo id='LsxIA'><pre id='LsxIA'><center id='LsxIA'></center></pre></bdo></b><th id='LsxIA'></th></span></q></dt></tr></i><div id='LsxIA'><tfoot id='LsxIA'></tfoot><dl id='LsxIA'><fieldset id='LsxIA'></fieldset></dl></div>
      2. <legend id='LsxIA'><style id='LsxIA'><dir id='LsxIA'><q id='LsxIA'></q></dir></style></legend>

              <tbody id='LsxIA'></tbody>
            1. <tfoot id='LsxIA'></tfoot>
              • <bdo id='LsxIA'></bdo><ul id='LsxIA'></ul>

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

                  本文介绍了相当于 mysql_num_rows 或 mssql_num_rows 的 PDO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道以前有人问过这个问题,但似乎解决方案是针对所提出的问题的.

                  I know this question has been asked before but it seems like the solutions have been specific to the problem presented.

                  我有一个包含数百个使用 mssql_num_rows 实例的代码库.

                  I have a codebase with hundreds of instances where mssql_num_rows is used.

                  代码示例:

                  $db->execute($sql);
                  
                  if ($db->getRowsAffected() > 0) {
                      $total = $db->fetch();
                  

                  在数据库类中:

                  $this->rowsaffected = mssql_num_rows($this->query_result);
                  

                  • 我无法创建通用的 SELECT count(*) FROM table 查询,因为我有太多特定的选择语句.
                  • 我可以运行 preg_replace 来删除 SELECT 和 FROM 之间的所有内容,然后用 COUNT(*) 替换并运行第二个查询但这假设所有查询都以某种方式设置.
                  • 我可以先fetchAll然后count()结果,但这意味着升级if语句的所有实例.
                    • I can't create generic SELECT count(*) FROM table queries as I have too many specific select statements.
                    • I could run a preg_replace to remove everything between SELECT and FROM and then replace with a COUNT(*) and run a second query but this assumes all queries are setup a certain way.
                    • I could fetchAll first then count() the results but that means upgrading all instances of the if statements.
                    • 那么,如果人们将他们的代码更新为 PDO,那么什么是最好的替代 *_num_rows 函数的方法.不是解决特定问题的东西,而是替代 *_num_rows 功能的东西.如果这是不可能的,以前是什么让它成为可能的?

                      So what is the best all around replacement to a *_num_rows function if people are updating their code to PDO. Not something that solves a specific problem, but something that replaces the functionality of *_num_rows. If that's not possible what allowed it to be possible before?

                      推荐答案

                      如果你想计算行数,你可以使用 PDO:

                      If you want to count the rows you can do this with PDO:

                      $sql = 'select * from users';
                      $data = $conn->query($sql);
                      $rows = $data->fetchAll();
                      $num_rows = count($rows);
                      

                      如 SELECT 语句与 PDO 一起使用时,无法直接计算行数.rowcount.php" rel="nofollow noreferrer">文档.

                      There is no way to directly count rows when using a SELECT statement with PDO as stated in the docs.

                      PDOStatement::rowCount() 返回受相应的最后一个 DELETEINSERTUPDATE 语句影响的行数PDOStatement 对象.

                      PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

                      仅在绝对需要计数时才进行行计数,否则您可以验证查询是否与其他方法一起使用.如果您希望从表中返回数千行,您也不应该使用此方法,而是在查询中使用 COUNT() 函数来执行计数.

                      Only do a row count if you absolutely need the count, otherwise you can verify that the query worked with other methods. You should also not use this method if you expect to be returning thousands of rows from a table, instead, use the COUNT() function in a query for just performing the count.

                      这篇关于相当于 mysql_num_rows 或 mssql_num_rows 的 PDO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO bind_param 是未定义的方法 下一篇:PDO::FETCH_ASSOC 未获取所有内容

                  相关文章

                  最新文章

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

                  <tfoot id='cEqL3'></tfoot>
                    <bdo id='cEqL3'></bdo><ul id='cEqL3'></ul>

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