mysql 數據庫連接類
class MySQL{//數據庫部分
var $DBServer = 'localhost';//服務器
var $DBName = '';//數據庫名稱
var $DBUser = '';//數據庫用戶
var $DBPass = '';//數據庫密碼
var $OnErrorResume = 1;//錯誤提示關閉
var $LinkID = 0;//連接句柄
var $QueryID = 0;//查詢句柄
var $ResultS = array();//查詢結果集
var $Error = '';//錯誤信息
function Connect($Srv = "",$Usr = "",$Pass = "",$DB = ""){//連接數據庫
if($Srv == "") $Srv = $this->DBServer;
if($Usr == "") $Usr = $this->DBUser;
if($Pass == "") $Pass = $this->DBPass;
if($DB == "") $DB = $this->DBName;
if($this->LinkID == 0){
$this->LinkID = @mysql_connect($Srv,$Usr,$Pass) or die("數據庫連接失敗,請聯系管理員修復此問題。");
}
@mysql_select_db($DB,$this->LinkID) or die("數據庫選擇失敗,請聯系管理員修復此問題。");
return $this->LinkID;
}
function Free(){//釋放查詢結果
@mysql_free_result($this->QueryID);
$this->QueryID = 0;
}
function RowS(){//查詢到的記錄總數
if(!$this->QueryID) return 0;
return @mysql_num_rows($this->QueryID);
}
function NextRecord(){//下一條記錄
if(!$this->QueryID) return 0;
$this->ResultS = @mysql_fetch_array($this->QueryID);
}
function Seek($seek){
if(!$this->QueryID) return 0;
@mysql_data_seek($this->QueryID,$seek);
}
function Query($Sql){//執行查詢
if($Sql == "") return 0;
if($this->LinkID == 0) $this->Connect();
if($this->QueryID) $this->Free();//釋放原來查詢結果
$this->QueryID = @mysql_query($Sql,$this->LinkID);
$this->Error = mysql_error($this->LinkID);
if(!$this->QueryID) exit("$Sql執行失敗.");
return $this->QueryID;
}
function GetRecord($Name){
if(!$this->QueryID) return 0;
return $this->ResultS[$Name];
}
}