Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. /*
  3. * Mysql database class - only one connection alowed
  4. */
  5. class Database {
  6. private $_connection;
  7. private static $_instance; //The single instance
  8. private $_host = "46.101.140.93:3306";
  9. private $_username = "uber";
  10. private $_password = "pass";
  11. private $_database = "db_signature";
  12. /*
  13. Get an instance of the Database
  14. @return Instance
  15. */
  16. public static function getInstance() {
  17. return new self();
  18. }
  19.  
  20. private function __construct() {
  21. error_reporting(E_ALL & ~E_WARNING);
  22. $this->_connection = new mysqli($this->_host, $this->_username,
  23. $this->_password, $this->_database);
  24.  
  25. }
  26.  
  27. private function __clone() { }
  28.  
  29. public function getConnection() {
  30. if ($this->__isErrors()) {
  31. return null;
  32. }
  33. else {
  34. return $this->_connection;
  35. }
  36.  
  37. }
  38.  
  39. private function __isErrors() {
  40. if(mysqli_connect_error()) {
  41. return true;
  42. }
  43. else {
  44. return false;
  45. }
  46. }
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement