index.php代码:<?php
include("D:\phpStudy\WWW\pphb\source\core.php");
new core;
?>
config/config.php代码<?php
$_config = array();
//数据库基本配置
$_config['db']['db_host'] = "127.0.0.1";
$_config['db']['db_user'] = "root";
$_config['db']['db_pwd'] = "root";
$_config['db']['db_name'] = "pphb";
?>
source/core.php代码
<?php
class core{
public function __construct(){
$this->_init_config();
$this->_init_db();
}
public function _init_config() {
$_config = array();
include("D:\phpStudy\WWW\pphb\config\config.php");
echo "文件已包含成功!";
}
public function _init_db() {
$link = @mysql_connect($_config['db']['db_host'],$_config['db']['db_user'],$_config['db']['db_pwd']) or die("连接数据库失败请纠正".mysql_error());
if($link){
echo "数据库连接成功";
}else{
echo "数据库连接失败";
}
}
}
?>
运行显示
文件已包含成功!连接数据库失败请纠正Access denied for user ''@'localhost' (using password: NO)
这是哪里出现问题了?
include("D:\phpStudy\WWW\pphb\source\core.php");
new core;
?>
config/config.php代码<?php
$_config = array();
//数据库基本配置
$_config['db']['db_host'] = "127.0.0.1";
$_config['db']['db_user'] = "root";
$_config['db']['db_pwd'] = "root";
$_config['db']['db_name'] = "pphb";
?>
source/core.php代码
<?php
class core{
public function __construct(){
$this->_init_config();
$this->_init_db();
}
public function _init_config() {
$_config = array();
include("D:\phpStudy\WWW\pphb\config\config.php");
echo "文件已包含成功!";
}
public function _init_db() {
$link = @mysql_connect($_config['db']['db_host'],$_config['db']['db_user'],$_config['db']['db_pwd']) or die("连接数据库失败请纠正".mysql_error());
if($link){
echo "数据库连接成功";
}else{
echo "数据库连接失败";
}
}
}
?>
运行显示
文件已包含成功!连接数据库失败请纠正Access denied for user ''@'localhost' (using password: NO)
这是哪里出现问题了?