如何解决这种警告?警告:mysqli_query()至少需要2个参数

时间:2019-05-12 16:02:08

标签: php mysqli

我尝试在PHP和MYSQL中制作OOP的CRUD,但是我只是被卡住了。

运行MySqliPHP 7Apache 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;
    }

} 

?>

我希望显示数据库,但不会。我收到以下警告:

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 个答案:

没有答案