Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. class DB{
  2.  
  3. public $hostname,$database,$username,$password;
  4.  
  5. public function __construct(){
  6.     $this->hostname = "";
  7.     $this->database = "";
  8.     $this->username = "";
  9.     $this->password = "";
  10.     $this->errors = array();
  11. }
  12.  
  13. private function connessione(){
  14.     mysql_connect($this->hostname,$this->username,$this->password) or $this->errors[] = mysql_error();
  15.     mysql_select_db($this->database) or $this->errors[] = mysql_error();
  16.     $this->PrintErrors();
  17. }
  18.  
  19. public function query($query){
  20.     $this->query = $query;
  21.     $this->result = mysql_query($this->query) or $this->errors[] = mysql_error();
  22.     if($this->result){
  23.         return $this->result;
  24.     }else{
  25.         $this->PrintErrors();
  26.     }
  27. }
  28.  
  29. public function PrintErrors(){
  30.     foreach(array_unique($this->errors) as $key=>$value){
  31.         if(!empty($value)){
  32.             echo "Errore : ".$value."<br/>";
  33.         }
  34.     }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement