国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

如何用PHP的頁面?zhèn)浞荨⒒謴?fù)Mysql數(shù)據(jù)庫中的數(shù)據(jù)表

2024-07-24 12:56:34
字體:
供稿:網(wǎng)友
<?        
  //備份數(shù)據(jù)  
    $i   =   0;  
    $crlf="/r/n";  
    $dbname="xgtqr";  
    global     $dbconn;  
    $dbconn   =   mysql_connect("localhost","root","root");  
    $db   =   mysql_select_db("xgtqr",$dbconn);  
    $tables   =   mysql_list_tables("xgtqr",$dbconn);  
    $num_tables   =   @mysql_numrows($tables);  
          while($i   <   $num_tables)  
          {    
                  $table   =   mysql_tablename($tables,   $i);  
   
                  print   $crlf;  
                  print   $crlf;  
   
                  echo   get_table_def($dbname,   $table,   $crlf).";$crlf$crlf";  
                  echo   get_table_content($dbname,   $table,   $crlf);  
                  $i++;  
          }  
   
  //定義抽取表結(jié)構(gòu)與數(shù)據(jù)  
   
   
  function   get_table_def($db,   $table,   $crlf)  
  {  
          global   $drop;  
   
          $schema_create   =   "";  
          if(!empty($drop))  
                  $schema_create   .=   "drop   table   if   exists   $table;$crlf";  
   
          $schema_create   .=   "create   table   $table   ($crlf";  
          $result   =   mysql_db_query($db,   "show   fields   from   $table");  
          while($row   =   mysql_fetch_array($result))  
          {  
                  $schema_create   .=   "       $row[field]   $row[type]";  
   
                  if(isset($row["default"])   &&   (!empty($row["default"])   ||   $row["default"]   ==   "0"))  
                          $schema_create   .=   "   default   '$row[default]'";  
                  if($row["null"]   !=   "yes")  
                          $schema_create   .=   "   not   null";  
                  if($row["extra"]   !=   "")  
                          $schema_create   .=   "   $row[extra]";  
                  $schema_create   .=   ",$crlf";  
          }  
          $schema_create   =   ereg_replace(",".$crlf."$",   "",   $schema_create);  
          $result   =   mysql_db_query($db,   "show   keys   from   $table");  
          while($row   =   mysql_fetch_array($result))  
          {  
                  $kname=$row['key_name'];  
                  if(($kname   !=   "primary")   &&   ($row['non_unique']   ==   0))  
                          $kname="unique|$kname";  
                    if(!isset($index[$kname]))  
                            $index[$kname]   =   array();  
                    $index[$kname][]   =   $row['column_name'];  
          }  
   
          while(list($x,   $columns)   =   @each($index))  
          {  
                    $schema_create   .=   ",$crlf";  
                    if($x   ==   "primary")  
                            $schema_create   .=   "       primary   key   ("   .   implode($columns,   ",   ")   .   ")";  
                    elseif   (substr($x,0,6)   ==   "unique")  
                          $schema_create   .=   "       unique   ".substr($x,7)."   ("   .   implode($columns,   ",   ")   .   ")";  
                    else  
                          $schema_create   .=   "       key   $x   ("   .   implode($columns,   ",   ")   .   ")";  
          }  
   
          $schema_create   .=   "$crlf)";  
          return   (stripslashes($schema_create));  
  }  
   
  //保存數(shù)據(jù)表的值  
  function   get_table_content($db,   $table,   $crlf)  
  {  
          $schema_create   =   "";  
          $temp   =   "";  
          $result   =   mysql_db_query($db,   "select   *   from   $table");  
          $i   =   0;  
          while($row   =   mysql_fetch_row($result))  
          {  
                  $schema_insert   =   "insert   into   $table   values   (";  
                  for($j=0;   $j<mysql_num_fields($result);$j++)  
                  {  
                          if(!isset($row[$j]))  
                                  $schema_insert   .=   "   null,";  
                          elseif($row[$j]   !=   "")  
                                  $schema_insert   .=   "   '".addslashes($row[$j])."',";  
                          else  
                                  $schema_insert   .=   "   '',";  
                  }  
                  $schema_insert   =   ereg_replace(",$",   "",   $schema_insert);  
                  $schema_insert   .=   ");$crlf";  
                  $temp   =   $temp.$schema_insert   ;  
                  $i++;  
          }  
          return   $temp;  
  }  
  ?>  
聯(lián)系qq:31443433
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 弥渡县| 罗城| 乌拉特中旗| 浮山县| 彰武县| 鹤峰县| 弋阳县| 罗源县| 新郑市| 台州市| 尉犁县| 博野县| 广德县| 东源县| 资兴市| 湘西| 建湖县| 万州区| 叙永县| 古田县| 旅游| 双江| 永福县| 江北区| 恩施市| 贞丰县| 喀喇沁旗| 固原市| 龙泉市| 康保县| 通渭县| 普兰县| 华亭县| 德令哈市| 大余县| 忻州市| 梧州市| 南汇区| 天门市| 拉萨市| 闽侯县|