<?php

class Database {
    private $host = 'ewg.dedicated.co.za'; // Replace with your host
    private $username = 'elegaysv_Code2'; // Replace with your username
    private $password = 'EWG2Cod!@#'; // Replace with your password
    private $database = 'elegaysv_lowveld_nuts_rsvp'; // Replace with your database name
    protected $conn;

    public function __construct() {
        $this->connect();
    }

    private function connect() {
        try {
            $dsn = "mysql:host=$this->host;dbname=$this->database";
            $options = [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
            ];

            $this->conn = new PDO($dsn, $this->username, $this->password);
            // echo "<pre>"; print_r($this->conn); die;
        } catch(PDOException $ex){
            die("Connection failed: " . $ex->getMessage());
        }
    }

    public function query($sql) {
        try {
            $stmt = $this->conn->prepare($sql);
            $stmt->execute();
            return $stmt;
        } catch(Exception $ex) {
            die("Query execution error: ".$ex->getMessage());
        }
    }
}

?>