Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. class database {
  3.  
  4. private $dbName = null, $dbHost = null, $dbPass = null, $dbUser = null;
  5. private static $instance = null;
  6.  
  7. private function __construct($dbDetails = array()) {
  8.  
  9. // Please note that this is Private Constructor
  10.  
  11. $this->dbName = $dbDetails['db_name'];
  12. $this->dbHost = $dbDetails['db_host'];
  13. $this->dbUser = $dbDetails['db_user'];
  14. $this->dbPass = $dbDetails['db_pass'];
  15.  
  16. // Your Code here to connect to database //
  17. $this->dbh = new PDO('mysql:host='.$this->dbHost.';dbname='.$this->dbName, $this->dbUser, $this->dbPass);
  18. }
  19.  
  20. public static function connect($dbDetails = array()) {
  21.  
  22. // Check if instance is already exists
  23. if(self::$instance == null) {
  24. self::$instance = new database($dbDetails);
  25. }
  26.  
  27. return self::$instance;
  28.  
  29. }
  30.  
  31. private function __clone() {
  32. // Stopping Clonning of Object
  33. }
  34.  
  35. private function __wakeup() {
  36. // Stopping unserialize of object
  37. }
  38.  
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement