0

i have written a database class script but whenever i try to fetch data(users)from the database i get a blank page without errors, dont really know what am doing cos i have tried my best. I have a successful connection to the database. My database connection script using pdo is below:

<?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!';
     }
     ?>

While my database class script is below:

<?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);         
        }


     }      
}







 ?>

i required my database connection script into my database class and their is successful connection. Thanks in advance.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
charlyo
  • 25
  • 1
  • 6

0 Answers0