Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. static public function getInstance()
  2. {
  3. if (!self::$_instance) {
  4. self::$_instance = new self();
  5. }
  6.  
  7. return self::$_instance;
  8. }
  9.  
  10. private function __clone()
  11. {
  12. }
  13.  
  14. public function getConnection($db_host, $db_port, $db_name, $db_user, $db_pass){
  15. $con_name = $db_host . '_' . $db_name;
  16.  
  17. try {
  18. if (!isset($this->connection[$con_name])) {
  19. $this->connection[$con_name] = new PDO('mysql:host=' . $db_host . ';port=' . $db_port . ';dbname=' . $db_name . ';charset=utf8', $db_user, $db_pass, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_TIMEOUT => 5));
  20. $this->connection[$con_name]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  21.  
  22. if (debugEnabled()) {
  23. exit('Failed to connect to DB: ' . $e->getMessage());
  24. }
  25.  
  26. return NULL;
  27.  
  28. if (debugEnabled()) {
  29. exit('Failed to connect to DB: ' . $d->getMessage());
  30. }
  31.  
  32. return NULL;
  33. }
  34. }
  35. catch (PDOException $e) {
  36. exit('Failed to connect to DB: ' . $e->getMessage());
  37. return NULL;
  38. }
  39. catch (Exception $d) {
  40. exit('Failed to connect to DB: ' . $d->getMessage());
  41. return NULL;
  42. }
  43.  
  44. return $db_host . '_'[$con_name];
  45. }
  46. }
  47.  
  48. function getConnection()
  49. {
  50. return DB::getInstance()->getConnection(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement