日期:2013-06-02  浏览次数:20469 次

<?        
  //备份数据  
    $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++;  
          }  
   
  //定义抽取表结构与数据  
   
   
  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);  
&n