• <bdo id='QXQ5N'></bdo><ul id='QXQ5N'></ul>
    <legend id='QXQ5N'><style id='QXQ5N'><dir id='QXQ5N'><q id='QXQ5N'></q></dir></style></legend><tfoot id='QXQ5N'></tfoot>

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

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

        使用 PDO 回显显示表中的所有行

        时间:2023-10-04

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

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

                <tbody id='yTNwr'></tbody>
            • <legend id='yTNwr'><style id='yTNwr'><dir id='yTNwr'><q id='yTNwr'></q></dir></style></legend>
                  <tfoot id='yTNwr'></tfoot>
                  本文介绍了使用 PDO 回显显示表中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 PDO 回显表的所有行,但遇到了问题.

                  I'm trying to echo out all the rows of a table using PDO but am running into trouble.

                  用旧的方式做我会这样做

                  With the old way of doing I'd have done it like

                  $result = mysql_query($sql);
                  while ($row = mysql_fetch_array($result)){
                     $title= $row['title'];
                     $body= $row['body'];
                  }
                  

                  但是我正在尝试使用 PDO;

                  But with PDO I'm trying;

                  $result = $db->prepare("SELECT title, body FROM post");
                  $result->execute();
                  
                  while ($row = $db->fetchAll(PDO::FETCH_ASSOC))
                  {
                  $title = $row['title'];
                  $body = $row['body'];
                  }
                  
                  echo $title;
                  echo $body;
                  

                  它一直给我调用未定义的方法 PDO::fetchAll()

                  Which keeps giving me Call to undefined method PDO::fetchAll()

                  做手册中给出的例子

                  <?php
                  $sth = $dbh->prepare("SELECT name, colour FROM fruit");
                  $sth->execute();
                  
                  /* Fetch all of the remaining rows in the result set */
                  print("Fetch all of the remaining rows in the result set:
                  ");
                  $result = $sth->fetchAll();
                  print_r($result);
                  ?>
                  

                  有效,但我认为我无法像使用 $row=['blah']; 那样控制各个列.我呢?它也像这样打印出来;比较丑:

                  Works, but I don't think I have control over the individual colums like I would with a $row=['blah']; do I? It also prints out like this; rather ugly:

                  Array ( [0] => Array ( [title] => 这是数据库中输入的测试标题[0]

                  Array ( [0] => Array ( [title] => This is the test title entered in the database[0]

                  需要做什么才能正确使用 PDO 来做到这一点?

                  What needs to be done to properly use PDO to do this?

                  推荐答案

                  change:

                  while ($row = $db->fetchAll(PDO::FETCH_ASSOC))
                  {
                  $title = $row['title'];
                  $body = $row['body'];
                  }
                  

                  到:

                  while ($row = $result->fetch(PDO::FETCH_ASSOC))
                  {
                  $title = $row['title'];
                  $body = $row['body'];
                  }
                  

                  这篇关于使用 PDO 回显显示表中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MS SQL Server 上的 ODBC 查询仅在 PHP PDO (FreeTDS) 中返 下一篇:PDO 语句的转义参数?

                  相关文章

                  最新文章

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

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

                    1. <tfoot id='nixyT'></tfoot>