Advertisement
lignite0

class Database

Nov 13th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. class Database
  4. {
  5.     private $instance;
  6.  
  7.     public function __construct($host, $username, $password, $name)
  8.     {
  9.         $this->instance = new mysqli($host, $username, $password, $name);
  10.  
  11.         if ($this->instance->connect_error) {
  12.             throw new Exception(sprintf(
  13.                 'Connect Error (%s): %s',
  14.                 $this->instance->connect_errno, $this->instance->connect_error
  15.             ));
  16.         }
  17.     }
  18.  
  19.     public function query($sql)
  20.     {
  21.         $result = $this->instance->query($sql);
  22.         return $result->fetch_all(MYSQLI_ASSOC);
  23.     }
  24.  
  25.     public function exec($sql)
  26.     {
  27.         return $this->instance->query($sql);    
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement