Home >Backend Development >PHP Tutorial >PHP database backup and restore function_PHP tutorial

PHP database backup and restore function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:05:14997browse

php database backup and restore function The article provides a backup and restore function, which is a function written in PHP that can be backed up and restored. It also supports saving the code locally after backup. Well, let’s take a look at the source code.

php tutorial database tutorial backup and restore function
The article provides a backup and restore function, which is a function written in PHP that can be backed up and restored. It also supports saving the code locally after backup. Well, let’s take a look at the source code.
*/

//Backup and restore function

function write_file($sql,$filename) {
$re=true;
if(fopen("./www.bKjia.c0m/".$filename,"w">!@$fp=fopen("./www.bKjia.c0m/".$filename,"w+")) {$ re=false; echo "failed to open target file";}
If(!@fwrite($fp,$sql)) {$re=false; echo "failed to write file";}
If(!@fclose($fp)) {$re=false; echo "failed to close target file";}
Return $re;
}
function down_file($sql,$filename){
ob_end_clean();
header("content-encoding: none");
header("content-type: ".(strpos($_server['http_user_agent'], 'msie') ? 'application/octetstream' : 'application/octet-stream'));

header("content-disposition: ".(strpos($_server['http_user_agent'], 'msie') ? 'inline; ' : 'attachment; ')."filename=".$filename);

header("content-length: ".strlen($sql));
header("pragma: no-cache");

header("expires: 0");
echo $sql;
$e=ob_get_contents();
ob_end_clean();
}

function writeable($dir){
if(!is_dir($dir)) {
@mkdir($dir, 0777);
}
if(is_dir($dir)){
If($fp = @fopen("$dir/test.test", 'w')){
                  @fclose($fp);
                @unlink("$dir/test.test");
                $writeable = 1;
         }else {
                  $writeable = 0;
}
}
return $writeable;
}

function make_header($table){
global $db;
$sql="drop table if exists `".$table."`;n";
$db->query("show create table ".$table);
$db->nextrecord();
$tmp=preg_replace("/n/","",$db->f("create table"));
$sql.=$tmp.";n";
Return $sql;
}

function make_record($table,$num_fields){
global $db;
$comma="";
$sql .= "insert into ".$table." values(";
for($i = 0; $i < $num_fields; $i++)
{$sql .= ($comma."'".mysql tutorial_escape_string($db->record[$i])."'"); $comma = ",";}
$sql .= ");n";
Return $sql;
}

function show_msg($msgs){
$i=0;
$tm1="

< b>Prompt message:
    ";
    While (list($k,$v)=each($msgs)){
              $i=$i+1;
               $t1="
  • $i.".$v."
  • ";
              $t=$t.$t1;
    }
    $tm2="
";
Return $tm1.$t.$tm2;
}

function pageend(){
exit();
}

function import($fname) {
global $db;
$sqls=file($fname);
          foreach($sqls as $sql){
        str_replace("r","",$sql);
        str_replace("n","",$sql);
If(!$db->query(trim($sql))) return false;
}
Return true;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630794.htmlTechArticlephp database backup and restore function article provides a backup and restore function, which is written in php and can be backed up and restored. function, and also supports saving the code locally after backup, okay...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn