<?php
$conn = mysql_connect(); // 连接mysql
mysql_select_db("test"); // 选择库
$filename = "mydata.mysql"; // 指定目标文件名
$path = str_replace("\\","/",getcwd())."/$filename"; // 指定服务器端保存路径
$query = "select * from test1 INTO OUTFILE '$path'";
mysql_query($query); // 执行查询
// 此时,查询结果已保存在由$path指定的文件里了// 以下是下载
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
readfile($path);
unlink($path);    // 删除文件?>