Php database backup restoration function _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Php database backup restoration function. The php database backup and restoration function article provides a backup and restoration function, which is a function that can be backed up or restored using php. It also supports saving code locally after backup, good php database backup and restoration function the article provides a backup and restoration function, which is a function that can be backed up or restored using php. It also supports saving code locally after backup, now let's look at the source code.

Php Tutorial database tutorial backup restoration function
The article provides a backup restoration function, which is a function that can be backed up or restored using php. It also supports saving the code to the local after backup. let's look at the source code below.
*/

// Backup restoration 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 '], 'msi ')? 'Application/etetstream': 'application/octet-stream '));

Header ("content-disposition:". (strpos ($ _ server ['http _ user_agent '], 'msi ')? '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 ="

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;
}
?>

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.