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

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

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

        使用 PDO 从 MySQL 获取结果

        时间:2023-09-20

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

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

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

                <i id='qUWhG'><tr id='qUWhG'><dt id='qUWhG'><q id='qUWhG'><span id='qUWhG'><b id='qUWhG'><form id='qUWhG'><ins id='qUWhG'></ins><ul id='qUWhG'></ul><sub id='qUWhG'></sub></form><legend id='qUWhG'></legend><bdo id='qUWhG'><pre id='qUWhG'><center id='qUWhG'></center></pre></bdo></b><th id='qUWhG'></th></span></q></dt></tr></i><div id='qUWhG'><tfoot id='qUWhG'></tfoot><dl id='qUWhG'><fieldset id='qUWhG'></fieldset></dl></div>
                  <tbody id='qUWhG'></tbody>
              • <tfoot id='qUWhG'></tfoot>
                • 本文介绍了使用 PDO 从 MySQL 获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 PDO 从我的表中检索数据,但我似乎无法向浏览器输出任何内容,我只是得到一个纯白色页面.

                  I'm trying to retrieve data from my table using PDO, only I can't seem to output anything to my browser, I just get a plain white page.

                  try {
                    // Connect and create the PDO object
                    $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
                    $conn->exec("SET CHARACTER SET utf8");      // Sets encoding UTF-8
                  
                          $lastIndex = 2;
                  
                          $sql = "SELECT * FROM directory WHERE id > :lastIndex AND user_active != '' LIMIT 20"
                          $sth = $conn->prepare($sql);
                          $sth->execute(array(':lastIndex' => $lastIndex));
                  
                          $c = 1;
                          while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
                              echo 'ALL STYLING ETC RESULTS HERE';
                          $c++;
                          }
                  
                    $conn = null;        // Disconnect
                  }
                  

                  推荐答案

                  EXAMPLE.这是你的 dbc 课

                  <?php
                  
                  class dbc {
                  
                      public $dbserver = 'server';
                      public $dbusername = 'user';
                      public $dbpassword = 'pass';
                      public $dbname = 'db';
                  
                      function openDb() {    
                          try {
                              $db = new PDO('mysql:host=' . $this->dbserver . ';dbname=' . $this->dbname . ';charset=utf8', '' . $this->dbusername . '', '' . $this->dbpassword . '');
                          } catch (PDOException $e) {
                              die("error, please try again");
                          }        
                          return $db;
                      }
                  
                      function getAllData($qty) {
                          //prepared query to prevent SQL injections
                          $query = "select * from TABLE where qty = ?";
                          $stmt = $this->openDb()->prepare($query);
                          $stmt->bindValue(1, $qty, PDO::PARAM_INT);
                          $stmt->execute();
                          $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
                          return $rows;
                      }    
                  ?>
                  

                  您的 PHP 页面:

                  <?php 
                  require "dbc.php";
                  
                  $getList = $db->getAllData(25);
                  
                  foreach ($getList as $key=> $row) {
                           echo $row['columnName'] .' key: '. $key;
                      }
                  

                  这篇关于使用 PDO 从 MySQL 获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP:使用 PDO 从 MySQL 检索图像 下一篇:PHP sqlsrv 驱动程序和 PDO 驱动程序之间的数据类型

                  相关文章

                  最新文章

                • <small id='Jtsby'></small><noframes id='Jtsby'>

                  <legend id='Jtsby'><style id='Jtsby'><dir id='Jtsby'><q id='Jtsby'></q></dir></style></legend>
                • <tfoot id='Jtsby'></tfoot>

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

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