我试图在 php 中制作一个简单的注册系统。我有一个名为 Admin(在控制器文件夹内)的类,它扩展了 DBConnection.php 类。Admin 类有一个注册方法,可以让广告注册,但有问题。'include_once' 发生错误,错误提示'Warning: include_once(../Database/DBConnection.php): failed to open stream: No such file or directory in C:\xampp\htdocs\WoodlandsAway\controller\Admin.php on第 15 行-----''警告:include_once(): 无法打开'../Database/DBConnection.php' 以包含在 C:\xampp\htdocs 中(include_path='C:\xampp\php\PEAR') \WoodlandsAway\controller\Admin.php 在第 15 行-----''致命错误:第 17 行的 C:\xampp\htdocs\WoodlandsAway\controller\Admin.php 中找不到类 'DBConnection''
这是我的 include_once 代码
include_once ('../Database/DBConnection.php');
--DBConnection.php
class DBConnection {
//put your code here
private $host;
private $user;
private $pass;
private $database;
private $conn;
function DBConnection() {
$this->host = 'localhost';
$this->user = 'root';
$this->pass = '';
$this->database = 'woodlands_away';
}
public function getConnections() {
$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->database) or
die($this->conn->error);
return $this->conn;
}
}
和 Admin.php
include_once ('../Database/DBConnection.php');
class Admin extends DBConnection {
public function Admin() {
parent::DBConnection();
}
public function signup($username, $password) {
$sql = "insert into users values(".$username.", ".$password.")";
return $this->getConnections()->query($sql);
}}