Home>Article>Backend Development> How to implement database backup in php (code)

How to implement database backup in php (code)

不言
不言 Original
2018-09-12 16:39:22 4506browse

The content of this article is about how to implement database backup (code) in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

public function dataBackup(){ $doc_root=$_SERVER['DOCUMENT_ROOT']; $file_path_name=$doc_root.'/sqlbackup';  //保存到的路径 $name='backup_'.date('YmdHis').".sql"; if(!file_exists($file_path_name)){ mkdir($file_path_name,0777); } $mysqldump_url='G:\phpstudy\PHPTutorial\MySQL\bin\mysqldump.exe';//mysqldump.exe的绝对路径,安装mysql自带的有,可以搜索一下路径 $host='127.0.0.1';//数据库所在的服务器地址 $User='root';//数据库用户名 $Password='root';//数据库密码 $databaseName='kuer';//数据库名 $process=$mysqldump_url." -h".$host." -u".$User." -p".$Password." ".$databaseName." >".$file_path_name."/".$name; $er=system($process);//system()执行外部程序,并且显示输出 if($er!==false){ echo json_encode('success!'); }else{ echo json_encode('error!'); } }

Related recommendations:

implement mysql database backup and linux automatic scheduled backup code in php

php backup database code (1/10)

The above is the detailed content of How to implement database backup in php (code). For more information, please follow other related articles on the PHP Chinese website!

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