我尝试在PHP和MYSQL中制作OOP的CRUD,但是我只是被卡住了。
运行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;
}
}
?>
我希望显示数据库,但不会。我收到以下警告:
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