Advertisement
lignite0

Database mysqli instance

Nov 13th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 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.         return $this->instance->query($sql);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement