淺析php常用數據庫備份類_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:淺析php實現大文件上傳源代碼一個比較 經典的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 **描 述:實現數據的導入導出,數據表結構的導入導出 ********************************************************/ // //包含Mysql數據庫操作文件 // require_once("MysqlDB.php"); /******************************************************* **類 名:MysqlDB ********************************************************/ class DBManagement implements IDBManagement { // //當前數據庫中所有的數據表的名字 // private $TablesName; // //默認路徑 // private $DefaultPath; // //當前要操作的數據庫名 // private $DatabaseName; // //操作數據庫的對象 // private $db; /******************************************************* **方 法 名:__construct **功能描述:創建一個DBManagement的對象 **輸入參數:$_DatabaseName-string<要操作的數據庫名,如果為空則從配置文件中讀取> ** $_DefaultPath-string<存儲數據的默認路徑,如果為空則從配置文件中讀取> **輸出參數:無 **返 回 值:無 ********************************************************/ 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的所有數據表的名字 **輸入參數:無 **輸出參數:無 **返 回 值:-array <$this->TablesName:$this->Database的所有數據表的名字> ********************************************************/ 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的所有數據表對應的數據文件的物理文件名 **輸入參數:無 **輸出參數:無 **返 回 值:-array <$DataFilesName:$與$this->Database的所有數據表對應的數據文件的物理文件名> ********************************************************/ 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 **功能描述:保存數據表的結構到install.sql文件中,目標路徑為$DefaultPath **輸入參數:無 **輸出參數:無 **返 回 值:- 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中所有數據表的結構 **輸入參數:無 **輸出參數:無 **返 回 值:- bool<返回為true表示所有數據表的結構備份成功; ** 為false表示全部或部分數據表的結構備份失敗> **作 者:林超旗 **日 期:2007-04-09 **修 改 人: **日 期: ********************************************************/ protected function BackupTableStructure() { $i=0; $sqlText=""; $this->GetTablesName(); $count=count($this->TablesName); // //取出所有數據表的結構 // 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如何輸出簡單動態WAP頁面WAP(無線通訊協議)是在數字移動電話、個人手持設備(PDA等)及計算機之間進行通訊的開放性全球標準。WAP應用結構非常類似于Internet,一個典型的WAP應用請求是這樣的:首先,具有WAP用戶代理功能的移動終端(WAP手機等)通過內部運行的微瀏覽器(MicroBrowser
相關PHP教程:
- 相關鏈接:
- 教程說明:
PHP教程-淺析php常用數據庫備份類
。