呵呵,那你看一下phpmyadmin这么写的不就知道了?

解决方案 »

  1.   

    仍然可以用mysqldump备份
    win下写个批处理文件dump.bat
    linux下写个shell文件dump.sh
    都是用来执行mysqldump命令,然后在php中用system函数调用这些文件。
      

  2.   

    1、直接执行外部命令;
    2、读取DB的所有表,再逐个fetcht各表内的数据
    3、循环输出sql语句;
      

  3.   

    上面没有第三点,呵呵,举个例子吧,数据部分你自己处理一下吧
    <pre>
    <?PHP$conn = mysql_connect("localhost","root","");
    mysql_select_db('mysql');
    $res = mysql_query('show tables;');
    while($row[]=mysql_fetch_array($res,MYSQL_NUM));
    array_pop($row);
    print_r($row);
    for ($i=0;$i<count($row);$i++){
    $tmpRes = mysql_query("SHOW CREATE TABLE {$row[$i][0]}");
    $createSql = mysql_fetch_array($tmpRes,MYSQL_NUM);
    $tmpTable = $row[$i][0];
    $sql = "select * from $tmpTable";
    $tmpRes = mysql_query($sql);
    while($dataRow[]=mysql_fetch_array($tmpRes,MYSQL_ASSOC)){}
    array_pop($dataRow);
    print_r($createSql);
    echo "<hr>";
    print_r($dataRow);
    }
    ?>
    </pre>
      

  4.   

    http://www.china-mt.net/sqlTool.rar
      

  5.   

    谢谢,总算写出来了,本来想自己来找的。懒得写。还自己写吧。
       function mysqldump() {
          global $mysql_db;
          $crlf = "\n";
          $drop = 0;
          $cmdEnd = ";";
          $tables = mysql_list_tables($mysql_db);
          $num_tables = @mysql_numrows($tables);
          if($num_tables == 0){
             echo " No Table Found .";
          }
          else {
             $str = "/* Dump Mysql Database Into Sybase Database Format */".$crlf;
             $str.= "/* From Mysql Database  :  $mysql_db               */".$crlf;
             $str.= "/* DateTime : ".date("Y-m-d h:i:s")."        */".$crlf;
             echo $str;
          }
          $i=0;
          while ($i < $num_tables) {
             $table = mysql_tablename($tables, $i++);
             $str = $crlf;
             $str.= "/*---------------------------------------------------------*/".$crlf;
             $str.= "/* Table Structure  for '$table'                           */".$crlf;
             $str.= "/*---------------------------------------------------------*/".$crlf;
             $str.= $crlf;
             echo $str;
             $tb = $this->get_table_def($table) ;         $tb_def = $tb[0];
             echo $tb_def;
             $tb_col = $tb[1];
             $tb_identity = $tb[2];
             $this->get_table_content($table,$tb_col,$tb_identity);
          }
       }
      

  6.   

    function get_table_def($table) {
                    $crlf = "\n";
                    $drop = 0;
                    $cmdEnd = ";";
            $schema_create = "";
               $identity = '';
            if(!empty($drop)){
            $schema_create .= "DROP TABLE $table $crlf ".$cmdEnd." $crlf ";
               }
            $schema_create .= "CREATE TABLE $table ($crlf";
               $result = mysql_query("SHOW FIELDS FROM $table") or mysql_die();                while ($row = mysql_fetch_array($result)) {
                  $schema_create .= "   $row[Field] $row[Type]";                        $col_def[$row[Field]] = $row[Type];                        if($row["Null"] == "YES"){   // mysql
                    $schema_create .= " NULL ";
                  }
                            else{
                                    $schema_create .= " NOT NULL ";
                            }
                            if(!empty($row["Default"])) {
                 $schema_create .= " DEFAULT '$row[Default]' ";
                    }
                            if($row["Extra"] != ""){
                                    $identity = $row[Field];
               $schema_create .= " $row[Extra]";
                  }                        $schema_create .= ",$crlf";
               }
            $schema_create = ereg_replace(",".$crlf."$", "", $schema_create);                $result = mysql_query("SHOW KEYS FROM $table") or mysql_die();                while ($row = mysql_fetch_array($result)){
            $kname=$row['Key_name'];
                  if(($kname != "PRIMARY") && ($row['Non_unique'] == 0))
                  $kname="UNIQUE|$kname";
            if(!is_array($index[$kname])){
                                     $index[$kname] = array();
                            }
            $index[$kname][] = $row['Column_name'];
               }
               while(list($x, $columns) = @each($index)){
                  if($x == "PRIMARY"){
               $schema_create .= ",$crlf";
                                     $schema_create .= "   PRIMARY KEY (" . implode($columns, ", ") . ")";
               }
            else if (substr($x,0,6) == "UNIQUE") {
                    $schema_create .= ",$crlf";
                                     $schema_create .= "   UNIQUE  (" . implode($columns, ", ") . ")";
               }
            else {
                     $schema_index .= " create index i_$x on $table (" . implode($columns, ", ") . ")".$crlf.$cmdEnd.$crlf;
               }
               }
            $schema_create .= "$crlf)".$crlf.$cmdEnd.$crlf;
               $schema_create .=$schema_index ;
            return array(stripslashes($schema_create),$col_def,$identity);
            }
      

  7.   

    function get_table_content($table,$col_def,$identity='')  {
          $drop = 0;
          $cmdEnd = ";";
          $crlf="\n";
          $i = 0;
          $cols = "";
                         //column name;
          $cols = "(";
          while(list($key,$val)=@each($col_def)) {
           $cols.=$key.",";
          }
          $cols = substr($cols,0,strlen($cols)-1).")";
          reset($col_def);      $str = $crlf;
          $str.= "/*---------------------------------------------------------*/".$crlf;
          $str.= "/* Dumping data for table '$table'                         */".$crlf;
          $str.= "/*---------------------------------------------------------*/".$crlf;
          $str.= $crlf;
          echo $str;      $result = mysql_query("SELECT * FROM $table") or mysql_die();   while ($row = mysql_fetch_array($result))  {
          $schema_insert = "INSERT INTO $table $cols VALUES(";      while(list($key,$val)=each($col_def)) {
             if(!isset($row[$key]))  {
                $schema_insert .= " NULL,";
             }
             elseif ($row[$key] != "") {
           /* &frac14;&AElig;&shy;&Egrave;&Atilde;&thorn;&laquo;&not;¤&pound;&macr;à&yen;&Icirc;¤&THORN;&cedil;&sup1; */
                $sub_val = substr($val,0,4);
                if($val=='int' || $val=='tinyint' || $val=='integer' || $val=='smallint' ||
              $sub_val=='nume' || $sub_val=='floa' || $sub_val=='deci' ||
              $sub_val=='doub' || $sub_val=='real')
              $schema_insert .= $row[$key].",";
           else if($val=='date' && $row[$key]=="0000-00-00")
              $schema_insert .= "'',";
           else   /* &brvbar;p&ordf;G&Auml;&aelig;&brvbar;ì&shy;&Egrave;&yen;]§t¤&THORN;&cedil;&sup1;,¤&pound;&not;O&yen;&Icirc;\,&brvbar;&Oacute;&not;O±&Auml;&yen;&Icirc; &shy;&laquo;&frac12;&AElig; &ordf;&ordm;¤è&brvbar;&iexcl; */
                   $schema_insert .= " '".str_replace("\\n","\\\\n",$this->addQuote($row[$key]))."',";
                   // $schema_insert .= " '".$this->addQuote($row[$key])."',";
             }
        else {
           $schema_insert .= " '',";
              }
          }
          $schema_insert = ereg_replace(",$", "", $schema_insert);
          $schema_insert .= ")";
          $schema_insert .= $crlf.$cmdEnd.$crlf;
          echo $schema_insert;
          reset($col_def);
          $i++;
       }   return (true);
    }
    function addQuote($str) {
       $str = str_replace("'","''",$str);
       return $str;
    }