【发布时间】:2016-05-20 13:42:02
【问题描述】:
我尝试了有关此主题的各种其他主题,但没有成功。所以我写了我的具体案例。我再说一遍,我已经尝试过其他线程,但尝试其他人建议我没有得到结果。
所以,我正在创建自己的小 cms,不是很有经验。 我的结构是这样的:
/includes/config.php (class config.php)
/index.php
/other.php
现在我想在一个文件夹中创建一个管理区域:
**/admin**
然后我会调用 config.php 文件以构建查询和其他所有内容,但我不能。我试过这个:
require_once $_SERVER['DOCUMENT_ROOT'] 。 '/includes/config.php';
但它不起作用,我该如何解决?
编辑:
包括/config.php
class db {
private $conn;
private $host;
private $user;
private $password;
private $baseName;
private $port;
private $Debug;
private $stmt;
function __construct($params=array()) {
$this->conn = false;
$this->host = 'localhost'; //hostname
$this->user = ''; //username
$this->password = ''; //password
$this->baseName = ''; //name of your database
$this->port = '3306';
$this->debug = true;
$this->connect();
}
function __destruct() {
$this->disconnect();
}
function connect() {
if (!$this->conn) {
try {
$this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->baseName.'', $this->user, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
}
catch (Exception $e) {
die('Error : ' . $e->getMessage());
}
if (!$this->conn) {
$this->status_fatal = true;
echo 'Connection DB failed';
die();
}
else {
$this->status_fatal = false;
}
}
return $this->conn;
}
function disconnect() {
if ($this->conn) {
$this->conn = null;
}
}
public function query($query){
$this->stmt = $this->conn->prepare($query);
}
public function bind($param, $value, $type = null){
if (is_null($type)) {
switch (true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($param, $value, $type);
}
public function execute(){
return $this->stmt->execute();
}
public function resultset(){
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function single(){
$this->execute();
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
public function rowCount(){
return $this->stmt->rowCount();
}
public function lastInsertId(){
return $this->conn->lastInsertId();
}
public function beginTransaction(){
return $this->conn->beginTransaction();
}
public function endTransaction(){
return $this->conn->commit();
}
public function cancelTransaction(){
return $this->conn->rollBack();
}
public function debugDumpParams(){
return $this->conn->debugDumpParams();
}
}
$database = 新数据库(); $pdo =& $数据库;
【问题讨论】:
-
../includes/config.php来自/admin/ -
不,
..表示您将返回上一个文件夹,对您来说,这是父文件夹,因此您可以访问配置文件。
标签: php