<?php

class jet
{ //Properties
  private $connection;
  private $sql;
  private $table_name;

   
   public function __construct($host ="ewg.dedicated.co.za" , $user ="elegaysv_Code2" , $password = "EWG2Cod!@#" , $dbname ="elegaysv_spar") {

    $this->connection = mysqli_connect($host, $user, $password, $dbname);

    if (mysqli_connect_errno()) { 
      return "Failed to connect to MySQL: "  . mysqli_connect_error();
      exit();
     }
   }

    public function query($table_name, $sql)
    {
        $this->sql = $sql;
        $this->table_name = $table_name;
        // if (!$this->check_table_exists($table_name)) {
        //     echo "[SQL] TABLE NAME DOES NOT EXIST OR IS INCORRECT $table_name";
        // }
        $result = mysqli_query($this->connection, $this->sql);

        if (mysqli_error($this->connection)) {
            echo "[SQL QUERY FAILED] on " . $_SERVER['REQUEST_URI'] . " at line " . __LINE__ . ": " . mysqli_error($this->connection) . "<br>";
            echo "[SQL QUERY]: " . $sql;
            exit();
        } else {
            if (stripos(trim($sql), 'INSERT') === 0) {
                return mysqli_insert_id($this->connection);
            } else {
                return $result;
            }
        }
    }
}

?>