Guest User

sdeddddddddddddd

a guest
Dec 23rd, 2015
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Db_connection
  4. {
  5. private static $_instance;
  6. private $link;
  7. private $db_host;
  8. private $db_name;
  9. private $db_user;
  10. private $db_password;
  11.  
  12. public static function getInstance() {
  13. if (!(self::$_instance instanceof self)) {
  14. self::$_instance = new self();
  15. }
  16. return self::$_instance;
  17. }
  18.  
  19. // Do not allow an explicit call of the constructor: $v = new Singleton();
  20. final private function __construct() {
  21.  
  22. $db_host = $GLOBALS['db_host'];
  23. $db_name = $GLOBALS['db_name'];
  24. $db_user = $GLOBALS['db_user'];
  25. $db_password = $GLOBALS['db_password'];
  26.  
  27. $this->db_host = $db_host;
  28. $this->db_name = $db_name;
  29. $this->db_user = $db_user;
  30. $this->db_password = $db_password;
  31. $this->openConnection();
  32. }
  33.  
  34. public function __destruct() {
  35. $this->closeConnection();
  36. }
  37.  
  38. // Do not allow the clone operation: $x = clone $v;
  39. final private function __clone() { }
  40.  
  41. function openConnection() {
  42. $this->link = mysqli_connect($this->db_host,$this->db_user,$this->db_password);
  43. }
  44.  
  45. function closeConnection() {
  46. mysqli_close($this->link);
  47. }
  48.  
  49. public function getDbConnection() {
  50. $db['link'] = $this->link;
  51. $db['db_name'] = $this->db_name;
  52. return $db;
  53. }
  54.  
  55. }
  56.  
  57. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×