i have 3 pages one for connect the DB
class Db{
private $dbUserName ="root";
private $dbName = "oop";
private $dbPas = "";
private $dbHost = "127.0.01";
public function __construct($dbUserName, $dbName, $dbPas, $dbHost)
{
$this->dbUserName = $dbUserName;
$this->dbName = $dbName;
$this->dbPas = $dbPas;
$this->dbHost = $dbHost;
$con = new PDO("mysql:host= $dbHost; $dbUserName,$dbName,$dbPas");
return $con ;
}
the 2 is
class User extends Db{
protected function getAllUser(){
$sql = "SELECT * FROM user";
$result = $this->connect()->query($sql);
$count = $result->rowCount();
// check if there'r date in the db
if($count > 0){
while($row = $result->fetchAll() ){
$data[] = $row;
}
return $data;
}
}
}
the 3 is
class ViewUser extends User{
public function ViewAllUser (){
$datas = $this->getAllUser();
foreach($datas as $data){
//echo the db rows
echo $data['uid']."</br>";
echo $data['pas']."</br>";
}
}
}
when I try to run them on another page:
<?php
include 'Db.php';
include 'User.php';
include 'ViewUser.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Oop</title>
</head>
<body>
<?php
$users = new ViewUser();
$users->ViewAllUser();
?>
</body>
</html>
i get a error:
Uncaught ArgumentCountError: Too few arguments to function Db::__construct(), 0 passed in /Users/mohamedelmasry/Documents/websites/oop/test.php on line 18 and exactly 4 expected in /Users/mohamedelmasry/Documents/websites/oop/Db.php:18 Stack trace: #0 /Users/mohamedelmasry/Documents/websites/oop/test.php(18): Db->__construct() #1 /Users/mohamedelmasry/.composer/vendor/laravel/valet/server.php(128): require('/Users/mohamede...') #2 {main} thrown in /Users/mohamedelmasr
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…