Guest User

Untitled

a guest
Aug 20th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2. class DB
  3. {
  4.     /**
  5.      * Set the properties
  6.      */
  7.     public $host;
  8.     public $username;
  9.     public $password;
  10.     public $database;
  11.     private $connection;
  12.    
  13.     public function setHost($host)
  14.     {
  15.         $this->host = $host;
  16.     }
  17.    
  18.     public function getHost()
  19.     {
  20.         return $this->host;
  21.     }
  22.    
  23.     public function setUsername($username)
  24.     {
  25.         $this->username = $username;
  26.     }
  27.    
  28.     public function getUsername()
  29.     {
  30.         return $this->username;
  31.     }
  32.    
  33.     public function setPassword($password)
  34.     {
  35.         $this->password = $password;
  36.     }
  37.    
  38.     public function getPassword()
  39.     {
  40.         return $this->password;
  41.     }
  42.  
  43.     public function setDatabase($database)
  44.     {
  45.         $this->database = $database;
  46.     }
  47.    
  48.     public function getDatabase()
  49.     {
  50.         return $this->database;
  51.     }
  52.    
  53.     /**
  54.      * Generate an error for the whole class
  55.      */
  56.     public function error($title, $message)
  57.     {
  58.         $output = '<div style="margin: 0; padding: 0; border: 2px solid #990000; color: #990000;">
  59.                         <div style="font-size: 14px; font-family: Calibri, Arial, Helvetica, sans-serif; font-weight: bold;">' . $title . '</div>
  60.                         <div style="font-size: 12px; font-family: Calibri, Arial, Helvetica, sans-serif; font-weight: normal;">' . $message . '</div>
  61.                    </div>';
  62.        
  63.         return $output;
  64.     }
  65.    
  66.     /**
  67.      * Make a connection to the database
  68.      */
  69.     public function connect()
  70.     {
  71.         if(!$this->connection = mysqli_connect(getHost(), getUsername(), getPassword(), getDatabase())
  72.         {
  73.             error(
  74.                 'Kon niet verbinden met de database!',
  75.                 'Host: ' . getHost() . '<br />
  76.                 Gebruikersnaam: ' . getUsername() . '<br />
  77.                 Wachtwoord: ********<br />
  78.                 Database: ' . getDatabase() . '<br />
  79.                 Error: ' . mysqli_error . ''
  80.             );
  81.         }
  82.         else
  83.         {
  84.             if(!mysqli_select_db($this->connection, getDatabase())
  85.             {
  86.                 error(
  87.                     'Verkeerde database geselecteerd!',
  88.                     'Host: ' . getHost() . '<br />
  89.                     Gebruikersnaam: ' . getUsername() . '<br />
  90.                     Wachtwoord: ********<br />
  91.                     Database: ' . getDatabase() . '<br />
  92.                     Error:  ' . mysqli_error() . ''
  93.                 );             
  94.             }
  95.         }
  96.     }
  97. }
  98. ?>
Add Comment
Please, Sign In to add comment