public function db_connect() { $mysqli = new \mysqli($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'], $this->config['db_name']); // if ($mysqli->connect_errno) { Response::error(503, "503 Service Unavailable (DB connection failed): " . $mysqli->connect_error); } Utils::log("MySQL DB CONNECTED: " . json_encode($mysqli->get_charset())); return $mysqli; }
private function getConnection() { try { return new MongoClient("mongodb://" . $this->config['user'] . ":" . $this->config['pass'] . "@127.0.0.1/" . $this->config['db']); } catch (MongoConnectionException $e) { Utils::log($e->getMessage()); Response::error(500, 'DB connection failed (MongoDB).'); } }
/** * @return PDO */ private function getConnection() { if (!is_null($this->connection)) { return $this->connection; } $connection = NULL; $host = $this->config['host']; $db = $this->config['db']; $user = $this->config['user']; $pass = $this->config['pass']; try { //$connection = new PDO("mssql:host=$host;dbname=$db;charset=UTF8", $user, $pass); $connection = new PDO("dblib:host={$host};dbname={$db};charset=UTF8", $user, $pass); //$connection = new PDO("sqlsrv:Server=$host;Database=$db", $user, $pass); //odbc:DRIVER=FreeTDS;SERVERNAME=mssql;DATABASE= $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Utils::log("DB CONNECTED"); return $connection; } catch (PDOException $e) { Response::error(500, 'DB connection failed (SQL): ' . $e->getMessage()); } }