Guest User

Untitled

a guest
Jul 14th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. class Config
  2. {
  3. const host = "localhost";
  4. const user = "root";
  5. const pass = "pass";
  6. const name = "name";
  7. }
  8.  
  9. final class Singleton extends Config
  10. {
  11. protected static $connection;
  12. protected static $database = null;
  13.  
  14. protected function Singleton () { }
  15. protected function __clone () { }
  16.  
  17. static function Prepare()
  18. {
  19. self::$connection = new mysqli
  20. (
  21. parent::host,
  22. parent::user,
  23. parent::pass,
  24. parent::name
  25. );
  26.  
  27. if (mysqli_connect_errno())
  28. {
  29. printf
  30. (
  31. "Connection Error: %s\n ", mysqli_connect_error()
  32. );
  33. } else { echo "Databse resource found."; }
  34. }
  35.  
  36. public static function Instance()
  37. {
  38. if (!isset(
  39. self::$database)) {
  40. self::$database = self::Prepare();
  41. }
  42. return self::$database;
  43. }
  44. }
  45.  
  46. $instance = Singleton::Instance();
Add Comment
Please, Sign In to add comment