You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
892 B

5 years ago
<?php
5 years ago
5 years ago
class DatabaseService {
5 years ago
protected $glob;
private $db_host;
private $db_name;
private $db_user;
private $db_password;
private $connection;
5 years ago
5 years ago
public function __construct() {
global $GLOBALS;
$this->glob =& $GLOBALS;
}
5 years ago
5 years ago
public function getConnection() {
5 years ago
5 years ago
$this->connection = null;
$this->db_host = $this->glob['CONF']['DB']['HOST'];
$this->db_name = $this->glob['CONF']['DB']['DB_NAME'];
$this->db_user = $this->glob['CONF']['DB']['USER'];
$this->db_password = $this->glob['CONF']['DB']['PASSWORD'];
5 years ago
5 years ago
try {
$this->connection = new PDO("mysql:host=" . $this->db_host . ";dbname=" . $this->db_name, $this->db_user, $this->db_password);
} catch(PDOException $exception) {
echo "Connection failed: " . $exception->getMessage();
5 years ago
}
5 years ago
return $this->connection;
}
5 years ago
}
?>