淺析php常用數(shù)據(jù)庫備份類(2)_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:淺析php實(shí)現(xiàn)大文件上傳源代碼一個(gè)比較 經(jīng)典的php大文件上傳源代碼,可成功運(yùn)行. functionfunction_upload($name,$newname=,$dir=upload) { global$_FILES,$ext; $return=; $time=time(); $upload=trim($_FILES[$name][’tmp_name’]); $upload_name=trim($_FILES[$name][’name’])
/******************************************************* **方 法 名: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 RestoreTableStructure() { $fileName=$this->DefaultPath."/Install.sql"; if(!file_exists($fileName)){echo "找不到表結(jié)構(gòu)文件,請確認(rèn)你以前做過備份!";exit;} $fp=fopen($fileName,"r"); $sqlText=fread($fp,filesize($fileName)); //$sqlText=str_replace("\r","",$sqlText); //$sqlText=str_replace("\n","",$sqlText); $sqlArray=explode("; ",$sqlText); try { $count=count($sqlArray); // //數(shù)組的最后一個(gè)為";",是一個(gè)無用的語句, // for($i=1;$i<$count;$i++) { $sql=$sqlArray[$i-1].";"; $result=$this->db->ExecuteSQL($sql); if(!mysql_errno()) { if($i%2==0){echo "數(shù)據(jù)表".($i/2)."的結(jié)構(gòu)恢復(fù)成功!\n";} } else { if($i%2==0) { echo "數(shù)據(jù)表".($i/2)."的結(jié)構(gòu)恢復(fù)失敗!\n"; exit(); } } } } catch(Exception $e) { $this->db->ShowError($e->getMessage()); $this->db->Close(); return false; } } /******************************************************* **方 法 名:ImportData **功能描述:導(dǎo)入$this->Database中所有數(shù)據(jù)表的數(shù)據(jù)從與其同名的.txt文件中,源路徑為$DefaultPath **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)導(dǎo)入成功; ** 為false表示全部或部分?jǐn)?shù)據(jù)表的數(shù)據(jù)導(dǎo)入失敗> **作 者:林超旗 **日 期:2007-04-09 **修 改 人: **日 期: ********************************************************/ function ImportData() { $DataFilesName=$this->GetDataFileName(); $count=count($this->TablesName); //$this->db->ExecuteSQL("set character set gbk"); for ($i=0;$i<$count;$i++) { //$DataFilesName[$i]=str_replace("\\","/",$DataFilesName[$i]) //echo $DataFilesName[$i]; $sqlLoadData="load data infile ’".$DataFilesName[$i]."’ into table ".$this->TablesName[$i]; $sqlCleanData="delete from ".$this->TablesName[$i]; //echo $sql."\n"; try { //$this->db->ExecuteSQL("set character set utf8"); //$this->db->ExecuteSQL("SET NAMES ’utf8’"); $this->db->ExecuteSQL($sqlCleanData); $this->db->ExecuteSQL($sqlLoadData); return true; //echo "數(shù)據(jù)導(dǎo)入成功!"; } catch (Exception $e) { $this->db->ShowError($e->getMessage()); return false; exit(); } } } /******************************************************* **方 法 名:ExportData **功能描述:導(dǎo)出$this->Database中所有數(shù)據(jù)表的數(shù)據(jù)到與其同名的.txt文件中,目標(biāo)路徑為$DefaultPath **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)導(dǎo)出成功; ** 為false表示全部或部分?jǐn)?shù)據(jù)表的數(shù)據(jù)導(dǎo)出失敗> ********************************************************/ function ExportData() { $DataFilesName=$this->GetDataFileName(); $count=count($this->TablesName); try { for ($i=0;$i<$count;$i++) { $sql="select * from ".$this->TablesName[$i]." into outfile ’".$DataFilesName[$i]."’"; if(file_exists($DataFilesName[$i])) { unlink($DataFilesName[$i]); } //$this->db->ExecuteSQL("SET NAMES ’utf8’"); $this->db->ExecuteSQL($sql); } return true; //echo "數(shù)據(jù)導(dǎo)出成功!"; } catch (Exception $e) { $this->db->ShowError($e->getMessage()); return false; exit(); } } /******************************************************* **方 法 名:BackupDatabase **功能描述:備份$this->Database中所有數(shù)據(jù)表的結(jié)構(gòu)和數(shù)據(jù) **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)庫備份成功; ** 為false表示全部或部分?jǐn)?shù)據(jù)表的數(shù)據(jù)庫備份失敗> ********************************************************/ function BackupDatabase() { try { $this->BackupTableStructure(); $this->ExportData(); return true; } catch (Exception $e) { $this->db->ShowError($e->getMessage()); return false; exit(); } } /******************************************************* **方 法 名:RestoreDatabase **功能描述:還原$this->Database中所有數(shù)據(jù)表的結(jié)構(gòu)和數(shù)據(jù) **輸入?yún)?shù):無 **輸出參數(shù):無 **返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)庫還原成功; ** 為false表示全部或部分?jǐn)?shù)據(jù)表的數(shù)據(jù)庫還原失敗> ********************************************************/ function RestoreDatabase() { try { $this->RestoreTableStructure(); $this->ImportData(); return true; } catch (Exception $e) { $this->db->ShowError($e->getMessage()); return false; exit(); } } } ?> |
分享:解析PHP如何輸出簡單動(dòng)態(tài)WAP頁面WAP(無線通訊協(xié)議)是在數(shù)字移動(dòng)電話、個(gè)人手持設(shè)備(PDA等)及計(jì)算機(jī)之間進(jìn)行通訊的開放性全球標(biāo)準(zhǔn)。WAP應(yīng)用結(jié)構(gòu)非常類似于Internet,一個(gè)典型的WAP應(yīng)用請求是這樣的:首先,具有WAP用戶代理功能的移動(dòng)終端(WAP手機(jī)等)通過內(nèi)部運(yùn)行的微瀏覽器(MicroBrowser
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-淺析php常用數(shù)據(jù)庫備份類(2)。