我試圖做一個簡單的註冊系統在PHP中。我有一個名爲Admin的類(內部控制器文件夾),它擴展了DBConnection.php類。管理員類有一個註冊方法讓adming註冊但在那裏遇到問題。錯誤發生在'include_once'處,並且錯誤顯示'Warning:include_once(../ Database/DBConnection.php):未能打開流:C:\ xampp \ htdocs \ WoodlandsAway \ controller \ Admin.php中沒有這樣的文件或目錄第15行----- ' '警告:include_once():在C:\ xampp中打開用於包含(include_path ='C:\ xampp \ php \ PEAR')的'../Database/DBConnection.php'失敗\ htdocs \ WoodlandsAway \ controller \ Admin.php on line 15 ----- ' '致命錯誤:Class'DBConnection'未在C:\ xampp \ htdocs \ WoodlandsAway \ controller \ Admin.php中找到第17行'include_once():未能打開流:沒有這樣的文件或目錄 - PHP
這裏是我的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);
}}
一旦你在你的目錄結構中進行驗證,你就可以使用相對路徑了,一個目錄上並檢查數據庫文件夾是否可用 – Hkachhia
試試'include_once(__DIR__。/../ Database/DBConnection.php')' – HtmHell
是admin.php也包含在內?還是你直接調用該文件? – Jeff