[請益] win下用.php備份mysql某資料表轉成excel檔

看板PHP作者 (iamcat)時間17年前 (2008/09/05 04:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
winxp + AppServ 不想用 phpmyadmin 裡面的方法 想要寫個 backup.php 來備份 mysql 裡 food 這資料表 ( 位於good資料庫裡面) 然後另存新檔成 excel 檔 請問該怎麼寫呢?? ==================== 網路上找到這個 <?php $DB_Server = "localhost"; $DB_Username = "user"; $DB_Password = "password"; $DB_DBName = "dbname"; $DB_TBLName = "tblname"; $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn@#t connect."); $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn@#t select database."); $file_type = "vnd.ms-excel"; $file_ending = "xls"; header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=mydowns.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); $now_date = date(@#Y-m-d H:i@#); $title = "數據庫名:$DB_DBName,數據表:$DB_TBLName,備份日期:$now_date"; $sql = "Select * from $DB_TBLName"; $ALT_Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn@#t select database"); $result = @mysql_query($sql,$Connect) or die(mysql_error()); echo("$title\n"); $sep = "\t"; for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); $i = 0; while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; $i++; } return (true); ?> ========= 可是我怎麼弄都弄不好 請問我該怎麼改?? 系統 winxp AppServ mysqldump.exe 檔在 C:\AppServ\MySQL\bin 帳號 root 密碼 www 資料庫 good 資料表 food 我怎用都用不好 該怎用呢?? 還是有別的辦法?? 謝謝大家.. :( -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.25.128.135
文章代碼(AID): #18m4EZIk (PHP)
文章代碼(AID): #18m4EZIk (PHP)