TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫(kù)備份功能示例
本文實(shí)例講述了TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫(kù)備份功能。分享給大家供大家參考,具體如下:
1、效果圖

2、下載擴(kuò)展類( \extands\org\Baksql.php)
3、在 \public\static 里新建一個(gè)data 文件夾用來(lái)存放 .sql 的文件
4、使用方法
controller
<?php
namespace app\index\controller;
use think\Controller;
class Backup extends Controller
{
//數(shù)據(jù)庫(kù)備份
public function bak(){
$type=input("tp");
$name=input("name");
$sql=new \org\Baksql(\think\Config::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
<!--我用的是 H+ 的模板,樣式可以自己調(diào)-->
<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>數(shù)據(jù)庫(kù)備份</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('備份數(shù)據(jù)的時(shí)間較長(zhǎng),確定要備份所有數(shù)據(jù)嗎?')"><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>序號(hào)</td>
<td>備份名稱</td>
<td>備份時(shí)間</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('備份還原后僅會(huì)顯示當(dāng)前備份的數(shù)據(jù)庫(kù)的信息,您確定還原備份嗎 ?')"><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('數(shù)據(jù)庫(kù)備份一旦刪除不可找回,您確定操作嗎?')"><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
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
- 在TP5數(shù)據(jù)庫(kù)中四個(gè)字段實(shí)現(xiàn)無(wú)限分類的示例
- tp5(thinkPHP5)框架數(shù)據(jù)庫(kù)Db增刪改查常見操作總結(jié)
- tp5(thinkPHP5)框架實(shí)現(xiàn)多數(shù)據(jù)庫(kù)查詢的方法
- tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例
- tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫(kù)的方法
- thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫(kù)并返回json數(shù)據(jù)實(shí)例
- thinkPHP5實(shí)現(xiàn)數(shù)據(jù)庫(kù)添加內(nèi)容的方法
- thinkphp5框架實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀取的數(shù)據(jù)轉(zhuǎn)換成json格式示例
- PHP7使用ODBC連接SQL Server2008 R2數(shù)據(jù)庫(kù)示例【基于thinkPHP5.1框架】
- ThinkPHP5.1框架數(shù)據(jù)庫(kù)鏈接和增刪改查操作示例
- 基于ThinkPHP5框架使用QueryList爬取并存入mysql數(shù)據(jù)庫(kù)操作示例
- ThinkPHP5.0框架實(shí)現(xiàn)切換數(shù)據(jù)庫(kù)的方法分析
相關(guān)文章
在Laravel 中實(shí)現(xiàn)是否關(guān)注的示例
今天小編就為大家分享一篇在Laravel 中實(shí)現(xiàn)是否關(guān)注的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-10-10
Laravel登錄失敗次數(shù)限制的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于Laravel登錄失敗次數(shù)限制的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
yii實(shí)現(xiàn)級(jí)聯(lián)下拉菜單的方法
這篇文章主要介紹了yii實(shí)現(xiàn)級(jí)聯(lián)下拉菜單的方法,需要的朋友可以參考下2014-07-07
app判斷鏈接參數(shù)后綴跳轉(zhuǎn)不同地址的方法
下面小編就為大家?guī)?lái)一篇app判斷鏈接參數(shù)后綴跳轉(zhuǎn)不同地址的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-09-09
PHP 只允許指定IP訪問(允許*號(hào)通配符過濾IP)
今天有朋友問我如何只允許指定IP訪問,默認(rèn)禁止其它ip訪問,腳本之家小編以前分享的是如何限制指定ip訪問,這里正好分享下,需要的朋友可以參考下2014-07-07
PHP隊(duì)列場(chǎng)景以及實(shí)現(xiàn)代碼實(shí)例詳解
這篇文章主要介紹了PHP隊(duì)列場(chǎng)景以及實(shí)現(xiàn)代碼實(shí)例詳解,有感興趣的同學(xué)可以跟著學(xué)習(xí)研究下2021-02-02
CI框架實(shí)現(xiàn)優(yōu)化文件上傳及多文件上傳的方法
這篇文章主要介紹了CI框架實(shí)現(xiàn)優(yōu)化文件上傳及多文件上傳的方法,結(jié)合實(shí)例形式詳細(xì)分析了CI框架優(yōu)化文件上傳及多文件上傳的實(shí)現(xiàn)思路與具體操作步驟,需要的朋友可以參考下2017-01-01

