本文實(shí)例講述了TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫備份功能。分享給大家供大家參考,具體如下:
1、效果圖
2、下載擴(kuò)展類( \extands\org\Baksql.php)
3、在 \public\static 里新建一個data 文件夾用來存放 .sql 的文件
4、使用方法
controller
?php
namespace app\index\controller;
use think\Controller;
class Backup extends Controller
{
//數(shù)據(jù)庫備份
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ù)庫備份/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ù)據(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>序號/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('備份還原后僅會顯示當(dāng)前備份的數(shù)據(jù)庫的信息,您確定還原備份嗎 ?')">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ù)庫備份一旦刪除不可找回,您確定操作嗎?')">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é)》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計有所幫助。
您可能感興趣的文章:- 在TP5數(shù)據(jù)庫中四個字段實(shí)現(xiàn)無限分類的示例
- tp5(thinkPHP5)框架數(shù)據(jù)庫Db增刪改查常見操作總結(jié)
- tp5(thinkPHP5)框架實(shí)現(xiàn)多數(shù)據(jù)庫查詢的方法
- tp5(thinkPHP5)框架連接數(shù)據(jù)庫的方法示例
- tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法
- thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫并返回json數(shù)據(jù)實(shí)例
- thinkPHP5實(shí)現(xiàn)數(shù)據(jù)庫添加內(nèi)容的方法
- thinkphp5框架實(shí)現(xiàn)數(shù)據(jù)庫讀取的數(shù)據(jù)轉(zhuǎn)換成json格式示例
- PHP7使用ODBC連接SQL Server2008 R2數(shù)據(jù)庫示例【基于thinkPHP5.1框架】
- ThinkPHP5.1框架數(shù)據(jù)庫鏈接和增刪改查操作示例
- 基于ThinkPHP5框架使用QueryList爬取并存入mysql數(shù)據(jù)庫操作示例
- ThinkPHP5.0框架實(shí)現(xiàn)切換數(shù)據(jù)庫的方法分析