Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2. namespace com\icemalta\jobapp\helper;
  3.  
  4. /**
  5. * Singleton to connect to the database.
  6. *
  7. * @author Keith Vassallo
  8. */
  9. class Connection {
  10. private static $_singleton;
  11. private $_connection;
  12.  
  13. const DB_USERNAME = 'root';
  14. const DB_PASSWORD = 'root';
  15. const DB_HOST = 'localhost';
  16. const DB_NAME = 'JobApplicationSystem';
  17.  
  18. private function __construct() {
  19. $this->_connection = new \PDO(
  20. 'mysql:host=' . self::DB_HOST . ';dbname=' . self::DB_NAME,
  21. self::DB_USERNAME,
  22. self::DB_PASSWORD);
  23. $this->_connection->exec("SET CHARACTER SET utf8");
  24. }
  25.  
  26. public static function getInstance(): Connection {
  27. if (is_null(self::$_singleton)) {
  28. self::$_singleton = new Connection();
  29. }
  30. return self::$_singleton;
  31. }
  32.  
  33. public function getHandler() {
  34. return $this->_connection;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement