Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class Database extends mysqli
  2. {
  3. private static
  4. $instance = null;
  5.  
  6. private
  7. $host = DB_HOST,
  8. $user = DB_USER,
  9. $password = DB_PASSWORD,
  10. $database = DB_DATABASE;
  11.  
  12. private function __construct()
  13. {
  14. @parent::__construct(
  15. $this->host,
  16. $this->user,
  17. $this->password,
  18. $this->database
  19. );
  20.  
  21. if (mysqli_connect_errno())
  22. {
  23. throw new Exception(
  24. mysqli_connect_error(),
  25. mysqli_connect_errno()
  26. );
  27. }
  28. }
  29.  
  30. public static function get_instance()
  31. {
  32.  
  33. if (!isset($instance)) {
  34. $c = __CLASS__;
  35. $instance = new $c;
  36. }
  37.  
  38. return $instance;
  39. }
  40.  
  41. public function __clone()
  42. {
  43. throw new Exception("Cannot clone ".__CLASS__." class");
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement