第一个类
class fatherCategory
{
var $mInforArray;
var $categoryInfoArray;
var $father_id;
function Initdata()
{
require_once("config.inc.php");
require_once("database.php");
//连接数据库
$db= new Database($DBHOST,$DBUSER,$DBPWD,$DBNAME);
//获取基本信息
$db->mSqlString="select * from m8_fatherCategory ";
//echo "father:".$db->mSqlString;
$db->Query();
$this->mInforArray=$db->mResultArray;
//print_r($db->mResultArray);
$db->__destruct();
}
}//第2个类class sonCategory
{
var $mInforArray;
var $father_id;
var $son_id;
function Initdata()
{
require_once("config.inc.php");
require_once("database.php");
//连接数据库
$db= new Database($DBHOST,$DBUSER,$DBPWD,$DBNAME);
//获取基本信息
$db->mSqlString="select * from m8_sonCategory where fatherCategory_id=".$this->$fatherName;
$db->Query();
$this->mInforArray=$db->mResultArray;
$db->__destruct();
}
}
class fatherCategory
{
var $mInforArray;
var $categoryInfoArray;
var $father_id;
function Initdata()
{
require_once("config.inc.php");
require_once("database.php");
//连接数据库
$db= new Database($DBHOST,$DBUSER,$DBPWD,$DBNAME);
//获取基本信息
$db->mSqlString="select * from m8_fatherCategory ";
//echo "father:".$db->mSqlString;
$db->Query();
$this->mInforArray=$db->mResultArray;
//print_r($db->mResultArray);
$db->__destruct();
}
}//第2个类class sonCategory
{
var $mInforArray;
var $father_id;
var $son_id;
function Initdata()
{
require_once("config.inc.php");
require_once("database.php");
//连接数据库
$db= new Database($DBHOST,$DBUSER,$DBPWD,$DBNAME);
//获取基本信息
$db->mSqlString="select * from m8_sonCategory where fatherCategory_id=".$this->$fatherName;
$db->Query();
$this->mInforArray=$db->mResultArray;
$db->__destruct();
}
}
{
//属性
public $mConnId; //连接标识
public $mSqlString; //连接语句
public $mResultArray; //执行select语句返回的结果数组
//构造函数
function Database($pHost,$pUser,$pPwd,$pDbName)
{
$this->mConnId=mysql_connect($pHost,$pUser,$pPwd);//建立连接
mysql_select_db($pDbName,$this->mConnId);//连接数据库
mysql_query("SET NAMES 'GB2312'");//防止乱码
}
//查询数据,返回值为对象数组,数组中的每一元素为一行记录构成的对象
function Query()
{
$i=0;
$query_result=mysql_query($this->mSqlString,$this->mConnId);
while ($row=mysql_fetch_object($query_result))
{
$this->mResultArray[$i++]=$row;
}
}
}
{
$i=0;
$query_result=mysql_query($this- >mSqlString,$this- >mConnId);
while ($row=mysql_fetch_object($query_result))
{
$this- >mResultArray[$i++]=$row;
}
}
}
没返回吧
$db= new Database($DBHOST,$DBUSER,$DBPWD,$DBNAME);
应该报错说是这个类已经加载吧
其实第二次类执行的时候
require_once("config.inc.php");
require_once("database.php");
上面2句没有执行,也就是不能获取配置的内容了
require("config.inc.php");
}
require_once("database.php");