出现错误 - 警告:DbQuery::__construct() 缺少参数 1

Getting Error - Warning: Missing argument 1 for DbQuery::__construct()

我正在使用以下代码创建与数据库的连接。但是给我错误警告:DbQuery::__construct() 缺少参数 1;

请给我解决方法并指出我的错误。以下是我的代码:

core.php

    //Database connection
class DbQuery{
    public $conn;
    private $host;
    private $user;
    private $pass;
    private $daba;

    public function __construct($ihost, $iuser, $ipass, $idaba){
        $this->host = $ihost;
        $this->user = $iuser;
        $this->pass = $ipass;
        $this->daba = $idaba;

        $this->conn = new mysqli($this->host, $this->user, $this->pass, $this->daba);

        if($this->conn->connect_errno){
            die("Failed to connect with database : (" . $this->conn->connect_errno . ")" . $this->conn->connect_errno);
        }
    }
}
    class GenQuery extends DbQuery{
    //EXECUTE QUERY
    function exeQuery($input){
        $result = mysqli_query($this->conn, $input);
        if(!$result){
            die("Invalid query : ". mysqli_error($this->conn));
        }
        return $result;
    }
    //SELECT QUERY
    function selQuery($selectItem, $tableName, $condName, $condValue){
        $n = sizeof($selectItem); 
        $m = sizeof($condValue);
        $l = sizeof($condName); 

        if($m == $l){
            for($j=0; $j<$n; $j++){
                if($j == 0){
                    $selectVal = $selectItem[$j];
                }
                else{
                    $selectVal .= ", " . $selectItem[$j];;
                }
            }

            for($i=0; $i<$m; $i++){
                if($i == 0){
                    $val = $condName[$i] . " = '" . $condValue[$i] . "'";
                }
                else{
                    $val .= " AND " . $condName[$i] . " = '" . $condValue[$i] . "'";
                }
            }
            $query = "SELECT " . $selectVal . " FROM " . $tableName . " WHERE " . $val;
            $result = $this->exeQuery($query);
            return $result;
        }
    }
    }

   class ProcessQuery extends GenQuery{
    function selUser($condValue){
        $selectItem = array('*');
        $condName = array('uid');
        $input = $this->selQuery($selectItem, 'mk_user', $condName, $condValue);
        if(mysqli_num_rows($input) > 0){
            while($frow = mysqli_fetch_assoc($input)){
                $res = $frow['uname'];
            }
            return $res;
        }
    }
 }

test.php:

    <?php

require 'core.php';
$db = new DbQuery('localhost', 'root', '', 'mkart');
$b = ['12'];
$qry = new processQuery();
echo $res = $qry->selUser($b);

?>

提前致谢。

这一行是你的问题:

$qry = new processQuery();

在您的 类 processQuery 中(间接地)扩展 DBQuery。 DbQuery 构造函数由 processQuery 继承,需要 $ihost$iuser$ipass$idaba 四个参数,但您在实例化时没有提供任何参数processUser.

您在两行之前实例化 $db 时提供了参数,但那是一个不同的对象,$qry 不会从它继承。

你可能需要

$qry = new processQuery('localhost', 'root', '', 'mkart');