Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. class Database
  4. {
  5.  
  6.     private $host = DB_HOST;
  7.     private $user = DB_USER;
  8.     private $password = DB_PASSWORD;
  9.     private $dbname = DB_NAME;
  10.  
  11.     private $connection;
  12.     private $error;
  13.  
  14.     public function __construct()
  15.     {
  16.         $this->connectToDB();
  17.     }
  18.  
  19.     // Connect to Database
  20.     private function connectToDB()
  21.     {
  22.         $this->connection = new mysqli($this->host, $this->user, $this->password, $this->dbname);
  23.         if (!$this->connection) {
  24.             $this->error = "Conection failed" . $this->connectToDB->connect_error;
  25.             return false;
  26.         }
  27.     }
  28.  
  29.     // Read Data
  30.     public function select($query)
  31.     {
  32.         $result = $this->link->query($query) or die($this->link->error . __LINE__);
  33.         if ($result->mysqli_num_rows > 0) {
  34.             return $result;
  35.         } else {
  36.             return false;
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement