//the following variables is defined and used for globles .
//for the different kinds of versions,you also can make two system database ,by using this variable to divid. var $Version = "demo"; //the URL address var $Url = ""; //the URL VARIABLES LIST var $UrlVariaList = ""; //Application CD var $AppCd = ""; //fuse code var $FuseCode = ""; //application directory var $AppRootDir = ""; function setGlbFuseCode($str){ $GLOBALS["DOU_FuseCode"] = $str; }
//This method is used to rederict to the page which you want
function redirect($pageURL){ echo "<SCRIPT language=\"JAVASCRIPT\">"; echo "location.href=\"".$pageURL."\""; echo "</SCRIPT>"; }
//this class is specially for the access of the different kind of database . class DBAccess{ //here will start to define the variables and some are const .
//the name of the DB server var $hostName = "LocalHost"; //the DB server's access port var $port = "3306"; //the user of the database var $userName = "root"; //the password of the DB user var $passWord = "admin"; //The name of the database var $databaseName = "temp"; /**** the type of the database,the values as the follows: 1.[MYSQL] -> mysql database 2.[MSSQL] -> microsoft sql server database //3.[ORACLE] -> oracle database //4.[ACCESS] -> microsoft access database
the default value is the mysql database. *****/ var $DBType = "MYSQL";
//the operation of the variable 'hostName' function setHostName($strName){ $this->hostName = $strName; }
function getHostName(){ return $this->hostName; }
//the operation of the variable 'port' function setPort($strPort){ $this->port = $strPort; }
function getPort(){ return $this->port; }
//the operation of the variable 'userName' function setUserName($strUserName){ $this->userName = $strUserName; }
function getUserName(){ return $this->userName; }
//the operation of the variable 'passWord' function setPassWord($strPassWord){ $this->passWord = $strPassWord; }
function getPassWord(){ return $this->passWord; }
//the operation of the variable 'DBType' function setDBType($dbType){ $this->DBType = $dbType; }
function getDBType(){ return $this->DBType; }
//the set varaibles function function setVariables($hostName,$userName,$passWord,$databaseName,$hostPort="3306",$dbType="MYSQL"){ $this->setHostName($hostName); $this->setUserName($userName); $this->setPassWord($passWord); $this->setPort($hostPort); $this->setDBType($dbType); $this->databaseName = $databaseName; } //the database connection function . //NOTE: You must set the variables such as the hostName,the port,the userName,the password //before you use this method,you can complete it by use function 'setVariables()' /**** the type of the database's values as the follows: 1.[MYSQL] -> mysql database 2.[MSSQL] -> microsoft sql server database //3.[ORACLE] -> oracle database //4.[ACCESS] -> microsoft access database
the default value is the mysql database. *****/ function DBConn(){
switch($this->DBType){ case "MYSQL" : mysql_connect($this->hostName,$this->userName,$this->passWord); break; case "MSSQL" : mssql_connect($this->hostName,$this->userName,$this->passWord); break; default : echo "The database type [".$this->DBType."]is not right ! Please set it by using the function of [setDBType()]."; break; }
} /*** function query($str){ var $resultSet=; switch($this->DBType){ case "MYSQL" : mysql_select_db($this->databaseName); $resultSet = mysql_query($str); break; case "MSSQL" : //mssql_select_db($this->databaseName); echo "Sorry ! MSSQL DB is not support now"; break; } return $resultSet; } ****/
我在a中定义了我要用的变量,而且针对现在的问题如果我在c文件中包含a,那么就不会出现未定义的错误了。
<?php
class GlobleVarias{
//the following variables is defined and used for globles .
//for the different kinds of versions,you also can make two system database ,by using this variable to divid.
var $Version = "demo";
//the URL address
var $Url = "";
//the URL VARIABLES LIST
var $UrlVariaList = "";
//Application CD
var $AppCd = "";
//fuse code
var $FuseCode = "";
//application directory
var $AppRootDir = ""; function setGlbFuseCode($str){
$GLOBALS["DOU_FuseCode"] = $str;
}
function setGlbAppRootDir(){
$temp = explode("?",$_SERVER['REQUEST_URI']);
$temp = explode("/",$temp[0]);
for($i=0;$i<sizeof($temp)-1;$i++){
$this->AppRootDir = $this->AppRootDir.$temp[$i];
}
$temp = explode("/",$_SERVER['SERVER_PROTOCOL']);
$tempStr = $tempStr.$temp[0]."://";
$tempStr = $tempStr.$_SERVER['SERVER_NAME'] ;
if($_SERVER['SERVER_PORT'] != "80"){
$tempStr = $tempStr.":".$_SERVER['SERVER_PORT'];
}
$GLOBALS["DOU_AppRootDir"] = strtolower($tempStr)."/".$this->AppRootDir."/app/";
$GLOBALS["DOU_SysRootDir"] = strtolower($tempStr)."/".$this->AppRootDir."/" ;
}
}
//This method is used to rederict to the page which you want
function redirect($pageURL){
echo "<SCRIPT language=\"JAVASCRIPT\">";
echo "location.href=\"".$pageURL."\"";
echo "</SCRIPT>";
}
//this class is specially for the access of the different kind of database .
class DBAccess{
//here will start to define the variables and some are const .
//the name of the DB server
var $hostName = "LocalHost";
//the DB server's access port
var $port = "3306";
//the user of the database
var $userName = "root";
//the password of the DB user
var $passWord = "admin";
//The name of the database
var $databaseName = "temp";
/****
the type of the database,the values as the follows:
1.[MYSQL] -> mysql database
2.[MSSQL] -> microsoft sql server database
//3.[ORACLE] -> oracle database
//4.[ACCESS] -> microsoft access database
the default value is the mysql database.
*****/
var $DBType = "MYSQL";
//the operation of the variable 'hostName'
function setHostName($strName){
$this->hostName = $strName;
}
function getHostName(){
return $this->hostName;
}
//the operation of the variable 'port'
function setPort($strPort){
$this->port = $strPort;
}
function getPort(){
return $this->port;
}
//the operation of the variable 'userName'
function setUserName($strUserName){
$this->userName = $strUserName;
}
function getUserName(){
return $this->userName;
}
//the operation of the variable 'passWord'
function setPassWord($strPassWord){
$this->passWord = $strPassWord;
}
function getPassWord(){
return $this->passWord;
}
//the operation of the variable 'DBType'
function setDBType($dbType){
$this->DBType = $dbType;
}
function getDBType(){
return $this->DBType;
}
//the set varaibles function
function setVariables($hostName,$userName,$passWord,$databaseName,$hostPort="3306",$dbType="MYSQL"){
$this->setHostName($hostName);
$this->setUserName($userName);
$this->setPassWord($passWord);
$this->setPort($hostPort);
$this->setDBType($dbType);
$this->databaseName = $databaseName;
}
//the database connection function .
//NOTE: You must set the variables such as the hostName,the port,the userName,the password
//before you use this method,you can complete it by use function 'setVariables()'
/****
the type of the database's values as the follows:
1.[MYSQL] -> mysql database
2.[MSSQL] -> microsoft sql server database
//3.[ORACLE] -> oracle database
//4.[ACCESS] -> microsoft access database
the default value is the mysql database.
*****/
function DBConn(){
switch($this->DBType){
case "MYSQL" :
mysql_connect($this->hostName,$this->userName,$this->passWord);
break;
case "MSSQL" :
mssql_connect($this->hostName,$this->userName,$this->passWord);
break;
default :
echo "The database type [".$this->DBType."]is not right ! Please set it by using the function of [setDBType()].";
break;
}
}
/***
function query($str){
var $resultSet=;
switch($this->DBType){
case "MYSQL" :
mysql_select_db($this->databaseName);
$resultSet = mysql_query($str);
break;
case "MSSQL" :
//mssql_select_db($this->databaseName);
echo "Sorry ! MSSQL DB is not support now";
break;
}
return $resultSet;
}
****/
}
?>
require("Application.php");
$temp = new GlobleVarias();
$temp->setGlbFuseCode("ind_input");
$temp->setGlbAppRootDir();
$fuseCodeArray = explode("_",$DOU_FuseCode);
switch($fuseCodeArray[0]){
case "ind" :
include($DOU_AppRootDir."input.php");
break;
default :
include("error.php");
break;
}
?>
<?php
$dbObj = new DBAccess();
?>
我也遇到过,郁闷死了~O~