淺析php常用數(shù)據(jù)庫備份類_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:淺析php實現(xiàn)大文件上傳源代碼一個比較 經(jīng)典的php大文件上傳源代碼,可成功運行. functionfunction_upload($name,$newname=,$dir=upload) { global$_FILES,$ext; $return=; $time=time(); $upload=trim($_FILES[$name][’tmp_name’]); $upload_name=trim($_FILES[$name][’name’])
php代碼: <?php /******************************************************* **文 件 名:DBManagement.php **描 述:實現(xiàn)數(shù)據(jù)的導(dǎo)入導(dǎo)出,數(shù)據(jù)表結(jié)構(gòu)的導(dǎo)入導(dǎo)出 ********************************************************/ // //包含Mysql數(shù)據(jù)庫操作文件 // require_once("MysqlDB.php"); /******************************************************* **類 名:MysqlDB ********************************************************/ class DBManagement implements IDBManagement { // //當(dāng)前數(shù)據(jù)庫中所有的數(shù)據(jù)表的名字 // private $TablesName; // //默認(rèn)路徑 // private $DefaultPath; // //當(dāng)前要操作的數(shù)據(jù)庫名 // private $DatabaseName; // //操作數(shù)據(jù)庫的對象 // private $db; /******************************************************* **方 法 名:__construct **功能描述:創(chuàng)建一個DBManagement的對象 **輸入?yún)?shù):$_DatabaseName-string<要操作的數(shù)據(jù)庫名,如果為空則從配置文件中讀取> ** $_DefaultPath-string<存儲數(shù)據(jù)的默認(rèn)路徑,如果為空則從配置文件中讀取> **輸出參數(shù):無 **返 回 值:無 ********************************************************/ function __construct($_DatabaseName="",$_DefaultPath="")// { require("config.inc.php"); if(!$_DatabaseName) {$this->DatabaseName=$dbName;} else {$this->DatabaseName=$_DatabaseName;} if(!$_DefaultPath) {$this->DefaultPath=$defaultPath;} else {$this->DefaultPath=$_DefaultPath;} $path=realpath($this->DefaultPath); $this->DefaultPath=str_replace("\\","/",$path); //$this->db=new DBFactory(); $this->db=new MysqlDB(); } /******************************************************* **方 法 名:GetTablesName **功能描述:獲取$this->Database的所有數(shù)據(jù)表的名字 **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:-array <$this->TablesName:$this->Database的所有數(shù)據(jù)表的名字> ********************************************************/ protected function GetTablesName() { $result=$this->db->Query("show table status"); while($Row=$this->db->NextRecord($result)) { $this->TablesName[]=$Row["Name"]; } return $this->TablesName; } /******************************************************* **方 法 名:GetDataFileName **功能描述:獲取與$this->Database的所有數(shù)據(jù)表對應(yīng)的數(shù)據(jù)文件的物理文件名 **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:-array <$DataFilesName:$與$this->Database的所有數(shù)據(jù)表對應(yīng)的數(shù)據(jù)文件的物理文件名> ********************************************************/ protected function GetDataFileName() { $this->GetTablesName(); $count=count($this->GetTablesName()); for ($i=0;$i<$count;$i++) { $DataFilesName[]=$this->DefaultPath."/".$this->TablesName[$i].".txt"; //echo $DataFilesName[$i]; } return $DataFilesName; } /******************************************************* **方 法 名:SaveTableStructure **功能描述:保存數(shù)據(jù)表的結(jié)構(gòu)到install.sql文件中,目標(biāo)路徑為$DefaultPath **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示保存成功; ** 為false表示保存失敗> **作 者:林超旗 **日 期:2007-04-09 **修 改 人: **日 期: ********************************************************/ protected function SaveTableStructure($text) { $fileName=$this->DefaultPath."/Install.sql"; //if(file_exists($fileName)) //{ // unlink($fileName); //} //echo $text; $fp=fopen($fileName,"w+"); fwrite($fp,$text); } /******************************************************* **方 法 名:RestoreTableStructure **功能描述:備份$this->Database中所有數(shù)據(jù)表的結(jié)構(gòu) **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的結(jié)構(gòu)備份成功; ** 為false表示全部或部分?jǐn)?shù)據(jù)表的結(jié)構(gòu)備份失敗> **作 者:林超旗 **日 期:2007-04-09 **修 改 人: **日 期: ********************************************************/ protected function BackupTableStructure() { $i=0; $sqlText=""; $this->GetTablesName(); $count=count($this->TablesName); // //取出所有數(shù)據(jù)表的結(jié)構(gòu) // while($i<$count) { $tableName=$this->TablesName[$i]; $result=$this->db->Query("show create table $tableName"); $this->db->NextRecord($result); // //取出成生表的SQL語句 // $sqlText.="DROP TABLE IF EXISTS `".$tableName."`; ";//` $sqlText.=$this->db->GetField(1)."; "; $i++; } $sqlText=str_replace("\r","",$sqlText); $sqlText=str_replace("\n","",$sqlText); //$sqlText=str_replace("’","`",$sqlText); $this->SaveTableStructure($sqlText); } |
分享:解析PHP如何輸出簡單動態(tài)WAP頁面WAP(無線通訊協(xié)議)是在數(shù)字移動電話、個人手持設(shè)備(PDA等)及計算機之間進行通訊的開放性全球標(biāo)準(zhǔn)。WAP應(yīng)用結(jié)構(gòu)非常類似于Internet,一個典型的WAP應(yīng)用請求是這樣的:首先,具有WAP用戶代理功能的移動終端(WAP手機等)通過內(nèi)部運行的微瀏覽器(MicroBrowser
相關(guān)PHP教程:
- 相關(guān)鏈接:
- 教程說明:
PHP教程-淺析php常用數(shù)據(jù)庫備份類。