无法使用数据库类从数据库表中获取数据

时间:2017-06-20 13:16:44

标签: php mysql

我已经编写了一个数据库类脚本,但每当我尝试从数据库中获取数据(用户)时,我都会得到一个没有错误的空白页面,不知道我在做什么,我已经尽了最大努力。我已成功连接到数据库。 我使用pdo的数据库连接脚本如下:

<?php 

$serverhost='localhost';
$serverdb='charles';
$serveruser='root';
$serverpassword='';




try{ 
    $connect= new PDO("mysql:host=$serverhost;dbname=charles;" , $serveruser, $serverpassword);
 $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } 
      catch( PDOException $e)
        {
        throw new exception($e->getmessage());
        }

     if($connect){
        echo 'database successful!';
     }
     ?>

我的数据库类脚本如下:

<?php
ini_set('display_errors','on');
require_once('connect.php');

class database {

private $fullname;
private $username;
private $password1;
private $email;
private $phonenumber;
private $alternativephonenumber;
private $referrer;
private $bankname;
private $Accountname;
private $Accountnumber;
private $AccountType;
private $PaymentMode;
private $AmountDonated;
private $connt;
private $AccountID;
private $OrderID;
private $ConfirmID;

//setting users in the database class
public function setUsers() {
      $this->fullname=$fullname;
      $this->username=$username;
      $this->password1=$password1;
      $this->email=$email;
      $this->phonenumber=$phonenumber;
      $this->alternativephonenumber=$alternativephonenumber;
      $this->referrer=$referrer;
      $this->PaymentMode=$PaymentMode;
      }

public function getUsers() {
      return $this->fullname=$fullname;
      return $this->username=$username;
      return $this->password1=$password1;
      return $this->email=$email;
      return $this->phonenumber=$phonenumber;
      return $this->alternativephonenumber=$alternativephonenumber;
      return $this->referrer=$referrer;
      return $this->PaymentMode=$PaymentMode;
      }
public function setServer() {
        $this->serverhost=$serverhost;
        $this->serveruser=$serveruser;
        $this->serverpassword=$password;
        $this->serverdb=$serverdb;
      }
public function getServer() {
       return $this->serverhost=$serverhost;
       return $this->serveruser=$serveruser;
       return $this->serverpassword=$serverpassword;
       return $this->serverdb=$serverdb;
      }        
// getting users data out from the database

public function checkusers() {
     $this->getServer();
    try {
         $connect= new PDO("mysql:host=$serverhost;dbname=charles;" , $serveruser, $serverpassword);
         $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $query= $connect->prepare("SELECT * FROM users WHERE username=':username' LIMIT 20");
         $query->bindParam(':username', $userid);
         $query->execute();
         if(!$query){
            echo "\nPDO::errorinfo():\n";
            print_r($query->errorinfo());
         }else{ echo 'yes';}
         while($row=$query->fetch(PDO::FETCH_ASSOC)){
         var_dump($row);
     }
            } 
            catch(PDOException $e) {
          throw new exception($e->getMessage);         
        }


     }      
}







 ?>

我需要将数据库连接脚本添加到我的数据库类中,并且它们是成功的连接。 提前谢谢。

0 个答案:

没有答案