TP5框架實現(xiàn)的數(shù)據(jù)庫備份功能示例
本文實例講述了TP5框架實現(xiàn)的數(shù)據(jù)庫備份功能。分享給大家供大家參考,具體如下:
1、效果圖
2、下載擴展類( \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('備份還原后僅會顯示當前備份的數(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
更多關于thinkPHP相關內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。
- 在TP5數(shù)據(jù)庫中四個字段實現(xiàn)無限分類的示例
- tp5(thinkPHP5)框架數(shù)據(jù)庫Db增刪改查常見操作總結
- tp5(thinkPHP5)框架實現(xiàn)多數(shù)據(jù)庫查詢的方法
- tp5(thinkPHP5)框架連接數(shù)據(jù)庫的方法示例
- tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法
- thinkPHP5實現(xiàn)的查詢數(shù)據(jù)庫并返回json數(shù)據(jù)實例
- thinkPHP5實現(xiàn)數(shù)據(jù)庫添加內(nèi)容的方法
- thinkphp5框架實現(xiàn)數(shù)據(jù)庫讀取的數(shù)據(jù)轉換成json格式示例
- PHP7使用ODBC連接SQL Server2008 R2數(shù)據(jù)庫示例【基于thinkPHP5.1框架】
- ThinkPHP5.1框架數(shù)據(jù)庫鏈接和增刪改查操作示例
- 基于ThinkPHP5框架使用QueryList爬取并存入mysql數(shù)據(jù)庫操作示例
- ThinkPHP5.0框架實現(xiàn)切換數(shù)據(jù)庫的方法分析
相關文章
Laravel登錄失敗次數(shù)限制的實現(xiàn)方法
這篇文章主要給大家介紹了關于Laravel登錄失敗次數(shù)限制的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08CI框架實現(xiàn)優(yōu)化文件上傳及多文件上傳的方法
這篇文章主要介紹了CI框架實現(xiàn)優(yōu)化文件上傳及多文件上傳的方法,結合實例形式詳細分析了CI框架優(yōu)化文件上傳及多文件上傳的實現(xiàn)思路與具體操作步驟,需要的朋友可以參考下2017-01-01