Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. class Donators{
  3.     protected $user;
  4.     protected $pass;
  5.     protected $dbname;
  6.     protected $dbhost;
  7.     protected $dbh; //db handle
  8.     protected $dbtable;
  9.    
  10.     public function __construct($user,$pass,$dbname,$dbhost,$dbtable){
  11.         $this->user = $user;
  12.         $this->pass = $pass;
  13.         $this->dbname = $dbname;
  14.         $this->dbhost = $dbhost;
  15.         $this->dbtable = $dbtable;
  16.     }
  17.     protected function connect(){
  18.         $this->dbh = mysql_connect($this->dbhost,$this->user,$this->pass);
  19.         if (!is_resource($this->dbh))
  20.             throw new Exception;
  21.         if (!mysql_select_db($this->dbname,$this->dbh))
  22.             throw new Exception;
  23.     }
  24.     protected function execute($query){
  25.         if (!$this->dbh) {
  26.             $this->connect();
  27.         }
  28.         $ret = mysql_query($query,$this->dbh);
  29.         if (!$ret){
  30.             throw new Exception;
  31.         } else if (!is_resource($ret)) {
  32.             return TRUE;
  33.         } else {
  34.             return $ret;
  35.         }
  36.     }
  37.     public function get_list(){
  38.         $q = "SELECT * FROM " . $this->dbtable;
  39.         $qresult = $this->execute($q);
  40.         $retval = array();
  41.         while ($row = mysql_fetch_assoc($qresult)){
  42.             $retval[] = $row;
  43.         }
  44.         return $retval;
  45.     }
  46. }
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement