日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

PHP數(shù)據(jù)庫備份類_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:解析php javascript 靜態(tài)化簡單實例
1.php生成js文件: 以下為引用的內(nèi)容: php代碼: ?php a=array( array('title'=>'本地新聞1',ln=>'#'), array('title'=&g

php代碼:

<?php
/*******************************************************
**文 件 名:DBManagement.php
**Copyright (c)2007-2008 ** 網(wǎng)站開發(fā)部
**文件編號:wtcms-lcq-db-004
**創(chuàng) 建 人:林超旗
**日 期:2007-04-07
**修 改 人:
**日 期:
**描 述:實現(xiàn)數(shù)據(jù)的導入導出,數(shù)據(jù)表結(jié)構(gòu)的導入導出
********************************************************/
//
//包含Mysql數(shù)據(jù)庫操作文件
//
require_once("MysqlDB.php");

/*******************************************************
**類 名:MysqlDB
**類 編 號:lcq-DB-003
**作 用:數(shù)據(jù)庫鏈接的建立,數(shù)據(jù)操作,獲取字段個數(shù),記錄條數(shù)等
**作 者:林超旗
**編寫日期:(2007-04-07)
********************************************************/
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ù):無
**返 回 值:無
**作 者:林超旗
**日 期:2007-04-09
**修 改 人:
**日 期:
********************************************************/
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ù)表的名字>
**作 者:林超旗
**日 期:2007-04-09
**修 改 人:
**日 期:
********************************************************/
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ù)文件的物理文件名>
**作 者:林超旗
**日 期:2007-04-09
**修 改 人:
**日 期:
********************************************************/
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
**功能描述:導入$this->Database中所有數(shù)據(jù)表的數(shù)據(jù)從與其同名的.txt文件中,源路徑為$DefaultPath
**輸入?yún)?shù):無
**輸出參數(shù):無
**返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)導入成功;
** 為false表示全部或部分數(shù)據(jù)表的數(shù)據(jù)導入失敗>
**作 者:林超旗
**日 期: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ù)導入成功!";
}
catch (Exception $e)
{
$this->db->ShowError($e->getMessage());
return false;
exit();
}
}
}

/*******************************************************
**方 法 名:ExportData
**功能描述:導出$this->Database中所有數(shù)據(jù)表的數(shù)據(jù)到與其同名的.txt文件中,目標路徑為$DefaultPath
**輸入?yún)?shù):無
**輸出參數(shù):無
**返 回 值:- bool<返回為true表示所有數(shù)據(jù)表的數(shù)據(jù)導出成功;
** 為false表示全部或部分數(shù)據(jù)表的數(shù)據(jù)導出失敗>
**作 者:林超旗
**日 期:2007-04-09
**修 改 人:
**日 期:
********************************************************/
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ù)導出成功!";
}
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ù)庫備份失敗>
**作 者:林超旗
**日 期:2007-04-10
**修 改 人:
**日 期:
********************************************************/
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ù)庫還原失敗>
**作 者:林超旗
**日 期:2007-04-10
**修 改 人:
**日 期:
********************************************************/
function RestoreDatabase()
{
try
{
$this->RestoreTableStructure();
$this->ImportData();
return true;
}
catch (Exception $e)
{
$this->db->ShowError($e->getMessage());
return false;
exit();
}
}
}
?>

分享:HTTP上PHP+JS實現(xiàn)安全地傳輸密碼
1、理論 在普通HTTP上,一般表單中的密碼都是以明文方式傳到服務(wù)器進行處理的。這無疑給了壞人以可乘之機!這里我們就說說怎么傳輸密碼才是安全的! 與其傳輸密碼本身,到不如傳輸其加

來源:模板無憂//所屬分類:PHP教程/更新時間:2008-12-04
相關(guān)PHP教程