Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. class Database extends MySQLi
  4. {
  5.     private $host, $user, $pass, $name;
  6.     private $connection, $result;
  7.  
  8.     public function __construct($host, $username, $password, $dbname)
  9.     {
  10.         $this->host = $host;
  11.         $this->user = $username;
  12.         $this->pass = $password;
  13.         $this->name = $dbname;
  14.  
  15.         $this->_connect();
  16.     }
  17.  
  18.     private function _connect()
  19.     {
  20.         $this->connection = new MySQLi($this->host, $this->user, $this->pass, $this->name);
  21.     }
  22.  
  23.     public function query($sql)
  24.     {
  25.         $this->result = $this->connection->query($sql);
  26.         return $this;
  27.     }
  28.  
  29.     public function fetchAll()
  30.     {
  31.         $obj = new stdClass();
  32.  
  33.         while($fetch = $this->result->fetch_object())
  34.         {
  35.             $obj = $fetch;
  36.         }
  37.  
  38.         return $obj;
  39.     }
  40. }
  41.  
  42. $db = new Database('localhost', 'root', '', 'test_db');
  43. $db->query("SELECT * FROM `tabelle`)->fetchAll();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement