中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php備份MYSQL類(lèi)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
<?php
/******   備份數(shù)據(jù)庫(kù)結(jié)構(gòu) ******/
/****正好要研究如何備份數(shù)據(jù)庫(kù),分享一個(gè)php實(shí)現(xiàn)MYSQL備份的類(lèi)庫(kù)********/
      /*
      函數(shù)名稱(chēng):table2sql()
      函數(shù)功能:把表的結(jié)構(gòu)轉(zhuǎn)換成為SQL
      函數(shù)參數(shù):$table: 要進(jìn)行提取的表名
      返 回 值:返回提取后的結(jié)果,SQL集合
      函數(shù)作者:heiyeluren
      */

     function table2sql($table)
      {
          global $db;
         $tabledump = "DROP TABLE IF EXISTS $table;\n";
         $createtable = $db->query("SHOW CREATE TABLE $table");
         $create = $db->fetch_row($createtable);
         $tabledump .= $create[1].";\n\n";
          return $tabledump;
      }

     /****** 備份數(shù)據(jù)庫(kù)結(jié)構(gòu)和所有數(shù)據(jù) ******/
      /*
      函數(shù)名稱(chēng):data2sql()
      函數(shù)功能:把表的結(jié)構(gòu)和數(shù)據(jù)轉(zhuǎn)換成為SQL
      函數(shù)參數(shù):$table: 要進(jìn)行提取的表名
      返 回 值:返回提取后的結(jié)果,SQL集合
      函數(shù)作者:heiyeluren
      */
     function data2sql($table)
      {
          global $db;
         $tabledump = "DROP TABLE IF EXISTS $table;\n";
         $createtable = $db->query("SHOW CREATE TABLE $table");
         $create = $db->fetch_row($createtable);
         $tabledump .= $create[1].";\n\n";

         $rows = $db->query("SELECT * FROM $table");
         $numfields = $db->num_fields($rows);
         $numrows = $db->num_rows($rows);
          while ($row = $db->fetch_row($rows))
          {
             $comma = "";
             $tabledump .= "INSERT INTO $table VALUES(";
              for($i = 0; $i < $numfields; $i++)
              {
                 $tabledump .= $comma."'".mysql_escape_string($row[$i])."'";
                 $comma = ",";
              }
             $tabledump .= ");\n";
          }
         $tabledump .= "\n";

          return $tabledump;
      }
?>


標(biāo)簽: Mysql 數(shù)據(jù)庫(kù)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:JAVA支持HTTP斷點(diǎn)續(xù)傳

下一篇:php調(diào)用solr封裝