Advertisement
Guest User

Untitled

a guest
May 17th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class DBConnect {
  4. private static $_singleton;
  5. private $_connection;
  6.  
  7. const DB_USERNAME = "root";
  8. const DB_PASSWORD = "";
  9. const DB_HOST = "localhost";
  10. const DB_NAME = "SimpleChat";
  11.  
  12. private function __construct() {
  13. $this->_connection = new PDO(
  14. 'mysql:host=' . self::DB_HOST . ';dbname=' . self::DB_NAME,
  15. self::DB_USERNAME,
  16. self::DB_PASSWORD
  17. );
  18.  
  19. $this->_connection->exec("SET CHARACTER SET utf8");
  20. }
  21.  
  22. public static function getInstance(): DBConnect {
  23. if(is_null(self::$_singleton)) {
  24. self::$_singleton = new DBConnect();
  25. }
  26. return self::$_singleton;
  27. }
  28.  
  29. public function getHandler(): PDO {
  30. return $this->_connection;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement