PHP database backup restore function _php Tutorial

Source: Internet
Author: User
Tags mysql tutorial php database
PHP Database backup Restore function article provides a backup restore function This is a function that can be backed up or restored using PHP, but also support the local code saved after backup Oh, well, look at the source below.

PHP Tutorial Database Tutorial Backup Restore function
The article provides a backup restore function this is the use of PHP written can be back up or can restore the function, but also support the backup after saving to the local code oh, well, look at the source below.
*/

Backup 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;
$tm 1 = "

Tip Information:
    ";
    while (list ($k, $v) =each ($msgs)) {
    $i = $i +1;
    $t 1 = "
  • $i. ". $v. "
  • ";
    $t = $t. $t 1;
    }
    $tm 2 = "
";
Return $TM 1. $t. $TM 2;
}

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

http://www.bkjia.com/PHPjc/630794.html www.bkjia.com true http://www.bkjia.com/PHPjc/630794.html techarticle PHP Database Backup restore function article provides a backup restore function This is a function that can be backed up or restored using PHP, but also support the code saved to the local after backup Oh, good ...

  • Related Article

    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.