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