<?php 
require_once ("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);
        
         if ($this->connection->connect_error) {
            die("Erro na conexão: " . $this->connection->connect_error);
        }

        // Define o charset da conexão
        if (!$this->connection->set_charset("utf8mb4")) {
            die("Erro ao definir charset: " . $this->connection->error);
        }
    }
    
    

    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();








?>