<?php 
require_once __DIR__ . "/new_config.php";

class Database{

    public $connection;

    function __construct(){
        $this->open_db_connection();
    }

    public function open_db_connection(){
        // $this->connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $this->connection = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);

         // Verifica erro de conexão
        if($this->connection->connect_errno){
            die("Erro de ligação à Base de Dados: " . $this->connection->connect_error);
        }

        // Define UTF-8 para toda a conexão
        $this->connection->set_charset("utf8mb4");

        // Opcional (alguns servidores antigos precisam disto)
        $this->connection->query("SET NAMES utf8mb4");
    }

    public function query($sql){
      
        $result = $this->connection->query($sql);
        return $result;
    }

    public function fetch_assoc($fetch){
        $fetch_all = mysqli_fetch_assoc($fetch);
        return $fetch_all;
    }

    public function escape_string($string){
       $escaped_string = $this->connection->real_escape_string($string);
       return $escaped_string;
    }

    public function the_insert_id(){
        return $this->connection->insert_id;
    }
    
 
    
 



 
}

$database = new Database();








?>