Advertisement
Guest User

Untitled

a guest
May 30th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <?php
  2. class Connect extends MySQLi{
  3.     private $host,$user,$pass,$dbas;
  4.     public function __construct($host=HOST,$user=USER,$pass=PASS,$dbas=DBAS){
  5.         parent::__construct($host,$user,$pass,$dbas);
  6.         $this->host = $host;
  7.         $this->user = $user;
  8.         $this->pass = $pass;
  9.         $this->dbas = $dbas;
  10.         $this->check();
  11.     }
  12.     private function check(){# connection
  13.         try{
  14.             if(mysqli_connect_error()) throw new Exception('Error connecting <em>'.$this->user.'</em> with password <em>'
  15.                     .$this->pass.'</em> to <em>'.$this->dbas.'</em> at <em>'.$this->host.'</em>.');
  16.             /*else echo nl2br('Connected <em>'.$this->user.'</em> with password <em>'.
  17.                     $this->pass.'</em> to <em>'.$this->dbas.'</em> at <em>'.$this->host.'</em>.'."\r\n");*/
  18.         }
  19.         catch(Exception $e){echo nl2br($e->getMessage().PNL);}
  20.     }
  21.     public function select($sql){# on success returns a result object
  22.         try{
  23.             if($this->result = parent::query($sql)){
  24.                 if($data = new Result($this->result)) return $data;
  25.                 else throw new Exception('Unable to return new Result at <b>'.__METHOD__.'</b>.');
  26.             }
  27.             else throw new mysqli_sql_exception('Possible SQL failure at <b>'.__METHOD__.'</b>.');
  28.         }
  29.         catch(Exception $e){echo nl2br($e->getMessage().PNL);}
  30.         catch(mysqli_sql_exception $e){echo nl2br($e->getMessage().' Code: '.$e->getCode().' Trace '.$e->getTraceAsString().PNL);}
  31.     }
  32.     public function query($sql){# on success returns true
  33.         try{
  34.             if($this->result = parent::query($sql)){
  35.                 echo 'Query was a success at <b>'.__METHOD__.'</b>.'.BR;
  36.                 return TRUE;
  37.             }
  38.             else throw new mysqli_sql_exception('Possible SQL failure at <b>'.__METHOD__.'</b>');
  39.         }
  40.         catch(Exception $e){echo nl2br($e->getMessage().PNL);}
  41.         catch(mysqli_sql_exception $e){echo nl2br($e->getMessage().' Code: '.$e->getCode().' Trace '.$e->getTraceAsString().PNL);}
  42.     }
  43.     public function close(){parent::close();}
  44.  
  45.     /*** FOR FRAMEWORK DEVELOPMENT ***/
  46.     public function ping(){return TRUE;}
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement