Advertisement
Guest User

Untitled

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