主頁(yè) > 知識(shí)庫(kù) > TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫(kù)備份功能示例

TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫(kù)備份功能示例

熱門標(biāo)簽:Linux服務(wù)器 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 服務(wù)器配置 團(tuán)購(gòu)網(wǎng)站 阿里云

本文實(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ù)的方法分析

標(biāo)簽:衡水 廣元 衢州 江蘇 蚌埠 大理 棗莊 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《TP5框架實(shí)現(xiàn)的數(shù)據(jù)庫(kù)備份功能示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266