Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public function getConnection($db_host, $db_port, $db_name, $db_user, $db_pass){
  2. $con_name = $db_host . '_' . $db_name;
  3.  
  4. try {
  5. if (!isset($this->connection[$con_name])) {
  6. $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));
  7. $this->connection[$con_name]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  8.  
  9. if (debugEnabled()) {
  10. exit('Failed to connect to DB: ' . $e->getMessage());
  11. }
  12.  
  13. return NULL;
  14.  
  15. if (debugEnabled()) {
  16. exit('Failed to connect to DB: ' . $d->getMessage());
  17. }
  18.  
  19. return NULL;
  20. }
  21. }
  22. catch (PDOException $e) {
  23. exit('Failed to connect to DB: ' . $e->getMessage());
  24. return NULL;
  25. }
  26. catch (Exception $d) {
  27. exit('Failed to connect to DB: ' . $d->getMessage());
  28. return NULL;
  29. }
  30.  
  31. return $db_host . '_'[$con_name];
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement