티스토리 뷰

 

접속된 DB의 설정된 테이블의 모든 데이터를 엑셀 파일로 다운로드 받는 소스 입니다.
===================================================
<?
$connect_host        = "localhost";
$connect_id        = "DB아이디";
$connect_pass        = "DB비밀번호";
$connect_db        = "DB이름";
$connect_table        = "테이블이름";
$xls_filename        = "filename.xls";

$connect=@mysql_connect($connect_host,$connect_id,$connect_pass);
$mysql=@mysql_select_db($connect_db,$connect);

header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$xls_filename");
?> 

<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=EUC-KR>
</head>
<body>
<table border=1>
<tr align=center>
<?
$fields = mysql_list_fields("$connect_db", "$connect_table");
$columns = mysql_num_fields($fields);

for ($i = 0; $i < $columns; $i++) {
$field[$i]=mysql_field_name($fields, $i);
  echo "<th>".$field[$i]. "</th>";
}
?>
</tr>

<?
$result=mysql_query("select * from $connect_table");
while($data=mysql_fetch_assoc($result)){
echo"<tr>";

for ($i = 0; $i < sizeof($field); $i++) {
echo "<td>".$data["$field[$i]"]."</td>";
}

echo"</tr>";
}
?>
</table>
</body>
</html>  


출처 : http://blog.naver.com/noend331/80004628361

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함