PHP database backup and restore function_PHP tutorial
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;
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
