<?php
	require_once __DIR__ . '/../../config/app.php';

	class Database{	 
		private $host;
		private $db_name;
		private $username;
		private $password;
		private $port;
		private $timezone;
		
		public $conn;

		public function __construct(){
			global $db_config;
			$this->host = $db_config['host'];
			$this->db_name = $db_config['name'];
			$this->username = $db_config['user'];
			$this->password = $db_config['pass'];
			$this->port = $db_config['port'];
			$this->timezone = $db_config['timezone'];
		}
	 
		public function getConnection(){
	 
			$this->conn = null;
	 
			try{
				// Create a new PDO connection
				$this->conn = new PDO(
					"mysql:host=" . $this->host . ";port=" . $this->port . ";dbname=" . $this->db_name . ";charset=utf8mb4",
					$this->username,
					$this->password
				);
				
				$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$this->conn->exec("SET time_zone = " . $this->conn->quote($this->timezone));
				
			}catch(PDOException $exception){
				echo "Connection error: " . $exception->getMessage();
			}
	 
			return $this->conn;
		}
	}
?>
