I try to make CRUD of OOP in PHP & MYSQL, but I just got stucked.

Running MySqli, PHP 7, Apache 3.

<?php 

class database{

    var $host = "localhost";
    var $uname = "root";
    var $pass = "";
    var $db = "dblatihan";

    function __construct(){
        mysqli_connect($this->host, $this->uname, $this->pass, $this->db);
    }
    function tampil_data(){
        $data = mysqli_query("select * from user");
        while($d = mysqli_fetch_array($data)){
            $hasil[] = $d;
        }
        return $hasil;
    }

} 

?>

I expect to show the database, but it doesn't. I get following warnings:

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\latihan\database.php on line 14

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\latihan\database.php on line 15

Notice: Undefined variable: hasil in C:\xampp\htdocs\latihan\database.php on line 18

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\latihan\tampil.php on line 19

0 Answers