<?php
class Database {
    private $host = "localhost";
    private $user = "root";
    private $pass = "";
    private $dbname = "wimas";
    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect($this->host, $this->user, $this->pass, $this->dbname);

        if (!$this->conn) {
            die("Database Connection Error: " . mysqli_connect_error());
        }
    }

    // Direct query execution - no binding
    public function query($sql) {
        $result = mysqli_query($this->conn, $sql);
        
        // If the query fails, print the exact SQL string to catch the mistake
        if (!$result) {
            die("<div style='background:#f8d7da; color:#721c24; padding:15px; border:1px solid #f5c6cb;'>
                    <strong>SQL Error:</strong> " . mysqli_error($this->conn) . "<br><br>
                    <strong>Failed Query:</strong> <code>" . $sql . "</code>
                 </div>");
        }
        
        return $result;
    }

    public function escape($value) {
        return mysqli_real_escape_string($this->conn, $value);
    }
}
?>