使用PHP将Mysql数据表导出到Excel中
2017-05-12 11:21
645 查看
//使用PHP将Mysql数据表导出到Excel中
<?php $db = 'test'; $table = 'article'; header("content-type:text/html;charset=utf-8"); @mysql_connect('localhost','root','123456'); mysql_set_charset('utf8'); mysql_select_db($db); $sql = "select * from $table"; $res = mysql_query($sql); $file_type = "vnd.ms-excel"; $file_ending = "xls"; header("content-type:application/$file_type"); header("content-Disposition: attachement; filename=$table.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); $time = date("Y-m-d H:i"); $title = "数据库名:$db,数据表名:$table,备份日期:$time"; echo "$title\n"; $sep = "\t"; for ($i=0; $i < mysql_num_fields($res); $i++) { echo mysql_field_name($res,$i)."\t"; } print("\n"); $i = 0; while ($row = mysql_fetch_row($res)) { $schema_insert = ""; for($j = 0;$j < mysql_num_fields($res); $j++){ if (!isset($row[$j])) { $schema_insert .= "NULL".$sep; } elseif($row[$j] != ""){ $schema_insert .= "$row[$j]".$sep; } else { $schema_insert .= "".$sep; } } $schema_insert .= "\t\n"; echo $schema_insert; $i++; }
相关文章推荐
- PHPExcel使用-使用PHPExcel导出文件-导出MySQL数据
- 使用JDBC+POI把Excel中的数据导出到MySQL
- php mysql数据导出excel
- PHP将mysql数据导出为Excel
- php导出数据到excel,防止身份证等数字字符格式变成科学计数的方-------缺点,必须使用table tr td
- 使用JDBC+POI把Excel中的数据导出到MySQL
- PHPExcel插件的使用1——基本数据导出
- 使用PHP导入Excel和导出数据为Excel文件
- 使用PHP导入Excel和导出数据为Excel文件
- PHP导出MySQL数据到Excel
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件(fputcsv)
- PHP_ThinkPHP使用phpExcel实现Excel数据的导出
- php、mysql导出excel数据
- php导出Mysql数据到Excel
- CI Codeigniter框架里面PHPExcel的使用|导出数据到Excel文件
- 转--使用PHP导入Excel和导出数据为Excel文件
- CI框架里面PHPExcel的使用|导出数据到Excel文件
- PHP将Excel表中的数据导入导出mysql
- 使用PHP导入Excel和导出数据为Excel文件