Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connect extends MySQLi{
- private $host,$user,$pass,$dbas;
- public function __construct($host=HOST,$user=USER,$pass=PASS,$dbas=DBAS){
- parent::__construct($host,$user,$pass,$dbas);
- $this->host = $host;
- $this->user = $user;
- $this->pass = $pass;
- $this->dbas = $dbas;
- $this->check();
- }
- private function check(){# connection
- try{
- if(mysqli_connect_error()) throw new Exception('Error connecting <em>'.$this->user.'</em> with password <em>'
- .$this->pass.'</em> to <em>'.$this->dbas.'</em> at <em>'.$this->host.'</em>.');
- /*else echo nl2br('Connected <em>'.$this->user.'</em> with password <em>'.
- $this->pass.'</em> to <em>'.$this->dbas.'</em> at <em>'.$this->host.'</em>.'."\r\n");*/
- }
- catch(Exception $e){echo nl2br($e->getMessage().PNL);}
- }
- public function select($sql){# on success returns a result object
- try{
- if($this->result = parent::query($sql)){
- if($data = new Result($this->result)) return $data;
- else throw new Exception('Unable to return new Result at <b>'.__METHOD__.'</b>.');
- }
- else throw new mysqli_sql_exception('Possible SQL failure at <b>'.__METHOD__.'</b>.');
- }
- catch(Exception $e){echo nl2br($e->getMessage().PNL);}
- catch(mysqli_sql_exception $e){echo nl2br($e->getMessage().' Code: '.$e->getCode().' Trace '.$e->getTraceAsString().PNL);}
- }
- public function query($sql){# on success returns true
- try{
- if($this->result = parent::query($sql)){
- echo 'Query was a success at <b>'.__METHOD__.'</b>.'.BR;
- return TRUE;
- }
- else throw new mysqli_sql_exception('Possible SQL failure at <b>'.__METHOD__.'</b>');
- }
- catch(Exception $e){echo nl2br($e->getMessage().PNL);}
- catch(mysqli_sql_exception $e){echo nl2br($e->getMessage().' Code: '.$e->getCode().' Trace '.$e->getTraceAsString().PNL);}
- }
- public function close(){parent::close();}
- /*** FOR FRAMEWORK DEVELOPMENT ***/
- public function ping(){return TRUE;}
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement