<?
include("conn.php"); //链接数据库
$filename = 'test.csv';
$fp = fopen($filename,'w');
if(!$fp){
echo "不能打开文件 $filename";
exit;
}
$csv_content = '';
$csv_content .= '测试字段1,';
$csv_content .= '测试字段2,';
$csv_content .= "\r";
$sql = "select * from `test`";
$query = mysql_query($sql);
while ( $rs = mysql_fetch_array($query) ){
$csv_content .= trim($rs["test1"]).',';
$csv_content .= trim($rs["test2"]).',';
$csv_content .= "\r";
}
mysql_free_result($query);
if (fwrite($fp, $csv_content) === FALSE) {
echo "不能写入到文件 $filename";
exit;
}
fclose($fp);
echo '文件 <a href="'.$filename.'" target="_blank">'.$filename.'</a> 生成成功!';
?>
include("conn.php"); //链接数据库
$filename = 'test.csv';
$fp = fopen($filename,'w');
if(!$fp){
echo "不能打开文件 $filename";
exit;
}
$csv_content = '';
$csv_content .= '测试字段1,';
$csv_content .= '测试字段2,';
$csv_content .= "\r";
$sql = "select * from `test`";
$query = mysql_query($sql);
while ( $rs = mysql_fetch_array($query) ){
$csv_content .= trim($rs["test1"]).',';
$csv_content .= trim($rs["test2"]).',';
$csv_content .= "\r";
}
mysql_free_result($query);
if (fwrite($fp, $csv_content) === FALSE) {
echo "不能写入到文件 $filename";
exit;
}
fclose($fp);
echo '文件 <a href="'.$filename.'" target="_blank">'.$filename.'</a> 生成成功!';
?>