php实现mysql数据库备份类

2019-04-10 23:14:54刘景俊

for ($i = 0; $i < mysql_num_rows($result); $i++){    
        array_push($tableList,mysql_tablename($result, $i));    
}    
mysql_free_result($result);    
return $tableList;    
}    

function _backupAllTable($dbName)    
{    
foreach ($this->_getTableList($dbName) as $tableName){    
$this->_TableBak->backupTable($tableName);    
}    
}    

function _backupOneTable($dbName,$tableName)    
{    
!in_array($tableName,$this->_getTableList($dbName)) && die("指定的表名<b>$tableName</b>在数据库中不存在");    
$this->_TableBak->backupTable($tableName);    
}    

function _backupSomeTalbe($dbName,$TableNameList)    
{    
foreach ($TableNameList as $tableName){    
!in_array($tableName,$this->_getTableList($dbName)) && die("指定的表名<b>$tableName</b>在数据库中不存在");    
}    
foreach ($TableNameList as $tableName){    
$this->_TableBak->backupTable($tableName);    
}    
}    

function _restoreAllTable($dbName)    
{    
//step1:检查是否存在所有数据表的备份文件 以及是否可写:    
foreach ($this->_getTableList($dbName) as $tableName){    
$tableBakFile = $this->_dataDir.DIRECTORY_SEPARATOR    
            . $dbName.DIRECTORY_SEPARATOR    
               . $tableName.DIRECTORY_SEPARATOR    
            . $tableName.'.sql';    
!is_writeable ($tableBakFile) && die("$tableBakFile not exists or unwirteable");    
}    
//step2:start restore    
foreach ($this->_getTableList($dbName) as $tableName){    
$tableBakFile = $this->_dataDir.DIRECTORY_SEPARATOR    
               . $dbName.DIRECTORY_SEPARATOR    
相关文章 大家在看