這是一款我在自己用時(shí)寫的一款利用php導(dǎo)出mysql數(shù)據(jù)庫(kù)的數(shù)據(jù)保存成csv文件,并提供下載,原理很簡(jiǎn)單就是把mysql數(shù)據(jù)查出來(lái),然后以csv格式保存到一個(gè).csv文件這樣就OK了,實(shí)例代碼如下:
- $times = time();
- $filename = $times.".csv";
- $a = "聯(lián)系人,聯(lián)系電話,申請(qǐng)時(shí)間 ";
- $days = postget("days");
- $mktime = daystomktime($days);
- $sql = "select * from v_tugou where ($times-times)<$mktime";
- $db = new db();
- $result = $db->query( $sql );
- $rs = $db->fetch($result,0);
- foreach($rs as $v=>$vv)
- {
- $a.=$vv['name'].','. $vv['mo'].",";
- $a.=date('y-m-d ',$vv['times'])." ";
- } //開(kāi)源代碼Vevb.com
- //echo $a;
- $hod = fopen ($filename,"w+");
- if( fwrite($hod,$a) )
- {
- echo "生成excel文件成功,點(diǎn)擊<a href=$filename target=_blank>右擊另存為excel文檔</a>";
- }
數(shù)據(jù)結(jié)構(gòu),代碼如下:
- -- 表的結(jié)構(gòu) `hn_tugou`
- --
- create table if not exists `v_tugou` (
- `id` int(4) not null auto_increment,
- `name` varchar(20) not null default '0',
- `mo` varchar(20) not null default '0',
- `times` int(4) default null,
- `ip` varchar(20) not null default '0',
- primary key (`id`)
- ) engine=myisam default charset=utf8 auto_increment=2 ;
- --
- -- 導(dǎo)出表中的數(shù)據(jù) `hn_tugou`
- --
- insert into `hn_tugou` (`id`, `name`, `mo`, `times`, `ip`) values
- (1, 'adsense', 'm.survivalescaperooms.com', 1283241159, '192.168.0.119');
新聞熱點(diǎn)
疑難解答