Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public function getInstance()
- {
- if (!self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- private function __clone()
- {
- }
- public function getConnection($db_host, $db_port, $db_name, $db_user, $db_pass){
- $con_name = $db_host . '_' . $db_name;
- try {
- if (!isset($this->connection[$con_name])) {
- $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));
- $this->connection[$con_name]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- if (debugEnabled()) {
- exit('Failed to connect to DB: ' . $e->getMessage());
- }
- return NULL;
- if (debugEnabled()) {
- exit('Failed to connect to DB: ' . $d->getMessage());
- }
- return NULL;
- }
- }
- catch (PDOException $e) {
- exit('Failed to connect to DB: ' . $e->getMessage());
- return NULL;
- }
- catch (Exception $d) {
- exit('Failed to connect to DB: ' . $d->getMessage());
- return NULL;
- }
- return $db_host . '_'[$con_name];
- }
- }
- function getConnection()
- {
- return DB::getInstance()->getConnection(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement