Advertisement
Guest User

Untitled

a guest
Mar 4th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class TConnection {
  5.  
  6. private $_connection;
  7. private static $_instance; //The single instance
  8. private $_host = "localhost";
  9. private $_username = "un";
  10. private $_password = "pw";
  11. private $_database = "db_maininfostore";
  12. /*
  13. Get an instance of the Database
  14. @return Instance
  15. */
  16. public static function getInstance() {
  17. if(!self::$_instance) { // If no instance then make one
  18. self::$_instance = new self();
  19. }
  20. return self::$_instance;
  21. }
  22. // Constructor
  23. private function __construct() {
  24. $this->_connection = new mysqli($this->_host, $this->_username,
  25. $this->_password, $this->_database);
  26.  
  27. // Error handling
  28. if(mysqli_connect_error()) {
  29. trigger_error("Failed to conencto to MySQL: " . mysql_connect_error(),
  30. E_USER_ERROR);
  31. }
  32. }
  33. // Magic method clone is empty to prevent duplication of connection
  34. private function __clone() { }
  35. // Get mysqli connection
  36. public function getConnection() {
  37. return $this->_connection;
  38. }
  39.  
  40.  
  41.  
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement