【发布时间】:2018-03-26 09:41:43
【问题描述】:
我试图在 php 中创建一个简单的注册系统。我有一个名为 Admin(在控制器文件夹内)的类,它扩展了 DBConnection.php 类。 Admin 类有一个注册方法,可以让广告注册,但有问题。 'include_once' 发生错误,错误提示'警告:include_once(../Database/DBConnection.php):无法打开流:C:\xampp\htdocs\WoodlandsAway\controller\Admin.php 中没有这样的文件或目录第 15 行----- ' '警告:include_once(): 未能打开 '../Database/DBConnection.php' 以在 C:\xampp\htdocs\WoodlandsAway\controller\Admin.php 中包含 (include_path='C:\xampp\php\PEAR')在第 15 行----- ' '致命错误:在第 17 行的 C:\xampp\htdocs\WoodlandsAway\controller\Admin.php 中找不到类 'DBConnection''
这是我的 include_once 代码
include_once ('../Database/DBConnection.php');
And here is my folder structure
--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);
}}
【问题讨论】:
-
您在包含中使用了相对路径一次,您可以在目录结构中验证,一个目录向上并检查数据库文件夹是否可用
-
试试
include_once (__DIR__ . '/../Database/DBConnection.php') -
admin.php 是否也包含在内?还是你直接调用那个文件?
标签: php mysql include-once