[Solved] how to bypass the Access denied for user ”@’localhost’ (using password: NO) bro [duplicate]


I think the issue here is scope.
You are setting your class variables and then when you are trying to reference them within your function you are not using $this->host for example but using $host. The $host variable within the function has not been initialized with a value within the function’s scope.

I haven’t tested the code below but I believe in your case it would be something like:

class Database {

    private $host = "localhost";
    private $username = "skander";
    public $password = "xxxxxx";
    private $db = "ishweb_skander";
    public $conn;

    public function dbConnection()
    {

        $this->conn = mysqli_connect($this->host, $this->username, $this->password,$this->db);

        if (!$this->conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        echo "connected successfully";
    }

}

solved how to bypass the Access denied for user ”@’localhost’ (using password: NO) bro [duplicate]