本文实例讲述了TP5框架实现的数据库备份功能。分享给大家供大家参考,具体如下:
1、效果图
2、下载扩展类( extandsorgBaksql.php)
3、在 publicstatic 里新建一个data 文件夹用来存放 .sql 的文件
4、使用方法
controller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php
namespace appindexcontroller;
use thinkController;
class Backup extends Controller
{
//数据库备份
public function bak(){
$type =input( "tp" );
$name =input( "name" );
$sql = new orgBaksql( hinkConfig::get( "database" ));
switch ( $type )
{
case "backup" : //备份
$info = $sql ->backup();
$this ->success( "$info" , 'index/backup/bak' );
break ;
case "dowonload" : //下载
$info = $sql ->downloadFile( $name );
$this ->success( "$info" , 'index/backup/bak' );
break ;
case "restore" : //还原
$info = $sql ->restore( $name );
$this ->success( "$info" , 'index/backup/bak' );
break ;
case "del" : //删除
$info = $sql ->delfilename( $name );
$this ->success( "$info" , 'index/backup/bak' );
break ;
default : //获取备份文件列表
return $this ->fetch( "bak" ,[ "list" => $sql ->get_filelist()]);
}
}
}
|
view
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<!--我用的是 H+ 的模板,样式可以自己调-->
<body class = "gray-bg" >
<div class = "wrapper wrapper-content animated fadeInRight" >
<div class = "row" >
<div class = "col-sm-12" >
<div class = "ibox float-e-margins" >
<div class = "ibox-title" >
<h5>数据库备份</h5>
<div class = "ibox-tools" >
<a class = "collapse-link" >
<i class = "fa fa-chevron-up" ></i>
</a>
</div>
</div>
<div class = "ibox-content" >
<div class = "" >
<a class = "btn btn-primary " href= "{:url('bak',['tp'=>'backup'])}" rel= "external nofollow" οnclick= "return confirm('备份数据的时间较长,确定要备份所有数据吗?')" ><i class = "glyphicon glyphicon-plus" ></i> <span class = "bold" >添加备份</span></a>
</div>
<table class = "table table-striped table-bordered table-hover dataTables-example" style= "text-align: center" >
<thead>
<tr>
<td>序号</td>
<td>备份名称</td>
<td>备份时间</td>
<td>备份大小</td>
<td>操作</td>
</tr>
</thead>
<tbody>
{volist name= "list" id= "vo" }
<tr class = "gradeX" >
<td>{ $key +1}</td>
<td>{ $vo .name}</td>
<td>{ $vo .time}</td>
<td>{ $vo .size}</td>
<td width= "25%" >
<a href= "{:url('bak',['tp'=>'dowonload','name'=>$vo.name])}" rel= "external nofollow" class = "btn btn-success " ><i class = "glyphicon glyphicon-download-alt" ></i> <span class = "bold" >下载</span></a>
<a href= "{:url('bak',['tp'=>'restore','name'=>$vo.name])}" rel= "external nofollow" class = "btn btn-info " οnclick= "return confirm('备份还原后仅会显示当前备份的数据库的信息,您确定还原备份吗 ?')" ><i class = "glyphicon glyphicon-repeat" ></i> <span class = "bold" >还原</span></a>
<a href= "{:url('bak',['tp'=>'del','name'=>$vo.name])}" rel= "external nofollow" class = "btn btn-warning" οnclick= "return confirm('数据库备份一旦删除不可找回,您确定操作吗?')" ><i class = "fa fa-warning" ></i> <span class = "bold" >删除</span></a>
</td>
</tr>
{/volist}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
|
5、Refresh the web page!!!over,over,over
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
原文链接:https://blog.csdn.net/weixin_42068782/article/details/84065101