国产又粗又硬又黄又爽_国产午夜夜伦鲁鲁片|HD中文字幕在线播放,午夜久久久久,亚洲国产中文字幕,美女奸三级日本电影

    電話

    0411-39943997

仟億科技
客服中心
  • 電話
  • 電話咨詢:0411-39943997
  • 手機
  • 手機咨詢:15840979770
    手機咨詢:13889672791
網(wǎng)絡(luò)營銷 >更多
您現(xiàn)在的位置:首頁 > 新聞中心 > 常見問題

大連網(wǎng)站制作:php基礎(chǔ):常用數(shù)據(jù)庫備份類

作者:billionnet 發(fā)布于:2011/12/19 15:35:21 點擊量:

php基礎(chǔ):常用數(shù)據(jù)庫備份類

 

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 

// 
//當前數(shù)據(jù)庫中所有的數(shù)據(jù)表的名字 
// 
private $TablesName; 
// 
//默認路徑 
// 
private $DefaultPath; 
// 
//當前要操作的數(shù)據(jù)庫名 
// 
private $DatabaseName; 
// 
//操作數(shù)據(jù)庫的對象 
// 
private $db; 

/******************************************************* 
**方 法 名:__construct 
**功能描述:創(chuàng)建一個DBManagement的對象 
**輸入?yún)?shù):$_DatabaseName-string<要操作的數(shù)據(jù)庫名,如果為空則從配置文件中讀取> 
** $_DefaultPath-string<存儲數(shù)據(jù)的默認路徑,如果為空則從配置文件中讀取> 
**輸出參數(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文件中,目標路徑為$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表示全部或部分數(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); 
}

/******************************************************* 
**方 法 名:RestoreTableStructure 
**功能描述:還原$this->Database中所有數(shù)據(jù)表的結(jié)構(gòu) 
**輸入?yún)?shù):無 
**輸出參數(shù):無 
**返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的結(jié)構(gòu)還原成功; 
** 為false表示全部或部分數(shù)據(jù)表的結(jié)構(gòu)還原失敗> 
**作 者:林超旗 
**日 期:2007-04-09 
**修 改 人: 
**日 期: 
********************************************************/ 
protected function RestoreTableStructure() 

$fileName=$this->DefaultPath."/Install.sql"; 
if(!file_exists($fileName)){echo "找不到表結(jié)構(gòu)文件,請確認你以前做過備份!";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ù)組的最后一個為";",是一個無用的語句, 
// 
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表示全部或部分數(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文件中,目標路徑為$DefaultPath 
**輸入?yún)?shù):無 
**輸出參數(shù):無 
**返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)導(dǎo)出成功; 
** 為false表示全部或部分數(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表示全部或部分數(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表示全部或部分數(shù)據(jù)表的數(shù)據(jù)庫還原失敗> 
********************************************************/ 
function RestoreDatabase() 

try 

$this->RestoreTableStructure(); 
$this->ImportData(); 
return true; 

catch (Exception $e) 

$this->db->ShowError($e->getMessage()); 
return false; 
exit(); 



?>

 

大連仟億科技大連網(wǎng)站建設(shè)大連網(wǎng)站制作大連網(wǎng)頁制作大連網(wǎng)頁設(shè)計大連網(wǎng)站設(shè)計大連網(wǎng)站推廣大連軟件開發(fā)大連網(wǎng)絡(luò)公司



分享到:


Copyright@ 2011-2016 版權(quán)所有:大連千億科技有限公司 遼ICP備11013762-3號   google網(wǎng)站地圖   百度網(wǎng)站地圖   網(wǎng)站地圖

公司地址:大連市沙河口區(qū)中山路692號辰熙星海國際2317 客服電話:0411-39943997 QQ:2088827823 37482752

法律聲明:未經(jīng)許可,任何模仿本站模板、轉(zhuǎn)載本站內(nèi)容等行為者,本站保留追究其法律責(zé)任的權(quán)利! 隱私權(quán)政策聲明