【发布时间】:2012-06-05 17:27:47
【问题描述】:
我有一个目录结构:
app
cofig
config.php
classes
db.class.php
index.php
config.php:
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'db_name');
db.class.php:
<?php
include "config/config.php";
class DB {
private $conn;
private $results;
public function __construct() {
$this->conn = mysql_connect(DB_HOST, DB_USER, DB_PASS);//**This doesn't work**
mysql_select_db(DB_NAME, $this->conn);
}
}
?>
当我尝试在 index.php 中创建 $db 类的实例时,出现错误(无法在类中获取 DEFINED 变量)
【问题讨论】:
-
确切的错误是什么?
-
这应该可以工作....你确定你有
require_once()'d config.php 吗? -
你使用了错误的配置文件还是它只是一个类型 o?您已导入 db.config 但在 config.php 中定义了变量
-
我已经编辑了代码,这是一个错字
标签: php