久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <tfoot id='zI5Kn'></tfoot>

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

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

          <bdo id='zI5Kn'></bdo><ul id='zI5Kn'></ul>
        <legend id='zI5Kn'><style id='zI5Kn'><dir id='zI5Kn'><q id='zI5Kn'></q></dir></style></legend>

        致命錯誤:調用未定義的方法 Database::prepare()

        Fatal error: Call to undefined method Database::prepare()(致命錯誤:調用未定義的方法 Database::prepare())
          <tbody id='E7xN9'></tbody>

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

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

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

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

                  本文介紹了致命錯誤:調用未定義的方法 Database::prepare()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我為數據庫和用戶創建了一個單獨的類.

                  I have created a separate class for database and users.

                  數據庫.php

                   class Database{
                  
                       private $db;
                  
                  
                      public function __construct(){
                  
                    /*** mysql hostname ***/
                  $hostname = 'localhost';
                  
                  /*** mysql username ***/
                  $username = 'username_web';
                  
                  /*** mysql password ***/
                  $password = 'password_web';
                  
                  
                  
                  try {
                      $this->db = new PDO("mysql:host=$hostname;dbname=kamadhenu_web", $username, $password);
                      /*** echo a message saying we have connected ***/
                  
                         }
                  catch(PDOException $e)
                      {
                      echo $e->getMessage();
                      }
                  
                   }
                  
                    /*** Query Function ***/
                   public function query($sql)
                          {
                          return $this->db->query($sql);
                          }
                  
                  
                  
                   }
                  

                  Users.php

                  class Users{
                  
                       private $db;
                  
                  public function __construct($database) {
                  $this->db = $database;
                  
                  }
                  
                  
                       public function login($username, $password)
                       {
                  
                          $query=$this->db->prepare("SELECT `password`, `id` FROM `users` WHERE `username` = ?");
                          $query->bindValue(1, $username);
                          try{
                          $query->execute();
                          $data = $query->fetch();
                          $stored_password = $data['password'];
                          $id = $data['id'];
                          #hashing the supplied password and comparing it with the stored hashed password.
                          if($stored_password === sha1($password)){
                          return $id; 
                          }else{
                          return false;   
                          }
                  
                          }catch(PDOException $e){
                          die($e->getMessage());
                  }
                  
                   }
                  
                  
                  
                  
                   }
                  

                  這是我的登錄頁面,包含用戶名和密碼.

                  Here is my Login page with username and password.

                   login.php
                  
                  include('database.php');
                  include('users.php');
                  
                  $dbh= new Database();
                  $users= new Users($dbh);
                  
                  
                  if (isset($_POST['submit']))
                  
                  { 
                  
                  $username= $_POST['username'];
                  $password= $_POST['password'];
                  
                      $login = $users->login($username, $password);
                  
                  
                  
                  
                          if ($login === false) {
                          $errors[] = 'Sorry, that username/password is invalid';
                          }
                          else {
                          // username/password is correct and the login method of the $users object returns the user's id, which is stored in $login.
                  
                          $_SESSION['id'] = $login; // The user's id is now set into the user's session in the form of $_SESSION['id']
                          #Redirect the user to home.php.
                          header('Location: list-updates.php');
                          exit();
                          }
                  
                  
                  
                  
                  
                  }
                  

                  執行時出現錯誤:

                  調用未定義的方法 Database::prepare()

                  Call to undefined method Database::prepare()

                  推薦答案

                  您在實例化 Database() 時創建了 $dbh,但是實例化 Database 只會返回您的 Database 類的實例,而不是您的數據庫連接.您應該有一個 getDb 來從數據庫對象獲取連接:

                  You create $dbh when you instantiate Database(), but instantiating the Database only returns an instance of your Database class, not your db connection. You should have a getDb to get your connection from database object:

                  $dbClass = new Database();
                  $dbh = $dbClass->getDb(); // here you get the connection
                  $users= new Users($dbh);  // here you give to Users() the $dbh, that isn't your 
                                            // connection.. it's just Database class
                  

                  數據庫構造僅返回數據庫類的實例,而不返回數據庫連接

                  class Database{
                  
                   private $db;
                  
                  
                  public function __construct(){
                  
                      try {
                       $this->db = new PDO("mysql:host=$hostname;dbname=kamadhenu_web", $username, $password);
                      /*** echo a message saying we have connected ***/
                  
                     }
                      catch(PDOException $e)
                          {
                              echo $e->getMessage();
                         }    
                   }
                  
                   public function getDb() {
                         if ($this->db instanceof PDO) {
                              return $this->db;
                         }
                   }
                  
                  
                  }
                  

                  這篇關于致命錯誤:調用未定義的方法 Database::prepare()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

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

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

                        <tbody id='dKqJs'></tbody>
                        <legend id='dKqJs'><style id='dKqJs'><dir id='dKqJs'><q id='dKqJs'></q></dir></style></legend>
                          <bdo id='dKqJs'></bdo><ul id='dKqJs'></ul>
                            <tfoot id='dKqJs'></tfoot>
                            主站蜘蛛池模板: 一级在线视频 | 日韩综合在线播放 | 在线视频成人 | 久久久久久综合 | 亚洲精彩免费视频 | 久久69精品久久久久久久电影好 | 免费精品视频一区 | 超碰在线97国产 | 一区二区在线观看av | 精品一区电影 | 国产精品视频久久 | 国产激情视频网站 | 日韩一区二区在线观看视频 | 一级毛片中国 | av中文在线观看 | 亚洲一二三区精品 | 国产精品美女久久久久久免费 | 涩涩视频在线观看 | 中文字幕亚洲精品 | 日韩欧美久久精品 | 丁香六月激情 | 国产91丝袜在线播放 | 一区二区三区四区在线 | 日韩一二三区视频 | 黄色av网站在线观看 | 成人黄色在线视频 | 97国产精品视频人人做人人爱 | www.国产| 91麻豆精品国产91久久久久久 | 国产色婷婷精品综合在线手机播放 | 国产精品免费视频一区 | 黄色一级特级片 | 91国产在线视频在线 | 国产激情 | 亚州精品天堂中文字幕 | 波霸ol一区二区 | 在线色网 | 国产一区二区在线免费 | 瑟瑟免费视频 | 成人视屏在线观看 | av网站在线看|