在student类中调用数据库类来执行查询

I have two main classes, Database & Student now I want to execute a query in studentDetail() method of Student Class. i.e.

But I am getting error that "Cannot redclare class Db in database_Class.php line:3"

studnet_Class.php

    include "database_Class.php";

 Class Student{
    private $db,$studentName;

    function __construct($DatabaseObj)
    {
        $this->db=$databaseObj;
    }

    public function studentDetail($ID)
    {
        $this->db->query("student",$ID);
    }
}

index.php

$db= new Db();
$student= new Student($db);

Replace:

include "database_Class.php";

by

include_once "database_Class.php";

This makes PHP including the file only if it hasn't included before.

I would further recommend to use require_once in favour of include_once to import a class. require_once will stop the script immediately throwing a fatal error if the file was not found. As a class file is an essential part of a program, only stopping the program immediately is a sufficient consequence.

I recommend to read the manual of