通过Cron工作每天发送电子邮件与数据库csv / xls或xml文件备份使用PHP在Linux服务器

这是我第一次尝试设置Cron Job。 我需要你的帮助。 我有db数据到csv / xls文件,但我不知道如何设置cron作业一次,每天通过这个文件通过电子邮件与数据。

带数据的数据库表

DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` int(11) NOT NULL auto_increment, `name` varchar(32) NOT NULL, `major` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; -- -- Dumping data for table `student` -- INSERT INTO `student` VALUES (1, 'John', 'Computer Science'); INSERT INTO `student` VALUES (2, 'Victor', 'Multimedia'); INSERT INTO `student` VALUES (3, 'Tomy', 'Networking'); INSERT INTO `student` VALUES (4, 'Will', 'Database'); INSERT INTO `student` VALUES (5, 'Jacky', 'Techincal'); 

data.php

 <table border="1"> <tr> <th>NO.</th> <th>NAME</th> <th>Major</th> </tr> <?php //connection to mysql mysql_connect("localhost", "root", ""); //server , username , password mysql_select_db("codelution"); //query get data $sql = mysql_query("SELECT * FROM student ORDER BY id ASC"); $no = 1; while($data = mysql_fetch_assoc($sql)){ echo ' <tr> <td>'.$no.'</td> <td>'.$data['name'].'</td> <td>'.$data['major'].'</td> </tr> '; $no++; } ?> </table> 

export.php

 <?php // The function header by sending raw excel header("Content-type: application/vnd-ms-excel"); // Defines the name of the export file "codelution-export.xls" header("Content-Disposition: attachment; filename=codelution-export.xls"); // Add data table include 'data.php'; ?> 

最后你需要这个文件codelution-export.xls 完整的代码

Interesting Posts