Advertisement
Guest User

PHP/MySQL Error

a guest
Oct 17th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. class MySQL {
  2.       public $host;
  3.       public $username;
  4.       public $password;
  5.       private $ref;
  6.       public function mysql() {
  7.       }
  8.       public function connect($host, $username, $password) {
  9.           $this->ref = @mysql_connect($host, $username, $password);
  10.           $this->host = $host;
  11.           $this->username = $username;
  12.           $this->password = $password;
  13.           if ($this->ref == false)
  14.               return false;
  15.           else
  16.               return true;
  17.       }
  18.       public function escape($string) {
  19.           $this->checkConnection();
  20.           return @mysql_real_escape_string($string, $this->ref);
  21.       }
  22.       public function getError() {
  23.           $this->checkConnection();
  24.           return mysql_error($this->ref);
  25.       }
  26.       public function selectDB($db) {
  27.           $this->checkConnection();
  28.           $newRes = @mysql_select_db($db, $this->ref);
  29.           if ($newRes == true)
  30.               return true;
  31.           else
  32.               return false;
  33.       }
  34.       public function query($query) {
  35.           $this->checkConnection();
  36.           return @mysql_query($query, $this->ref);
  37.       }
  38.       public function getRows($query) {
  39.           $this->checkConnection();
  40.           $result = $this->query($query);
  41.           return @mysql_num_rows($result);
  42.       }
  43.       public function returnArray($query) {
  44.           $this->checkConnection();
  45.           $result = $this->query($query);
  46.          
  47.           if (@mysql_num_rows($result) != 0) {
  48.               $arr = array();
  49.               while ($row = @mysql_fetch_assoc($result))
  50.                   $arr[] = $row;
  51.               return $arr;
  52.           } else
  53.               return array();
  54.       }
  55.       public function checkConnection() {
  56.           @$this->connect($this->host, $this->username, $this->password);
  57.       }
  58.       public function disconnect(){
  59.           return @mysql_close($this->ref);
  60.       }
  61.       public function __destruct(){
  62.           $this->disconnect();
  63.           sleep(4);
  64.       }
  65.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement