我有一个目录结构:
app
cofig
config.php
classes
db.class.php
index.php
配置.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 变量)