我正在寻找一种方法来自动插入行到mysql。目前,我正在使用php cron来实现这一点,但在mysql中,这些值看起来并不完美。
我应该怎么做才能清楚地获得附加值,例如:
2018-04-30 13:50:00
2018-04-30 13:51:00
2018-04-30 13:52:00
2018-04-30 13:53:00
2018-04-30 13:54:00
2018-04-30 13:55:00
2018-04-30 13:56:00
2018-04-30 13:57:00
我想这样做,因为这是重要的,我做分析,并删除所有空数据,如果存在。下面的脚本是用php制作的60秒cron。
$date = date('Y-m-d H:i:s');
/* Define functions */
function write_cron($timestamp, $cron_name, $var_name) {
$filename = realpath(dirname(__FILE__)).'/times/'.$cron_name.'.php';
$content = file_put_contents($filename, '<? $'.$var_name.'[\'time\'] = \''.$timestamp.'\'; ?>');
$return = true;
if (!$content) {
die('<center><b>System ERROR</b><br /><i>system/cron/times/'.$cron_name.'.php</i> must be writable (change permissions to 777)</center>');
$return = false;
}
return $return;
}
/* Times */
$timestamp = time();
$daily_time = strtotime(date('j F Y'));
$realPath = realpath(dirname(__FILE__));
if (!is_writable($realPath.'/times')) {
die('<center><b>System ERROR</b><br /><i>system/cron/times/</i> directory must be writable (change permissions to 777)</center>');
}
if (file_exists($realPath.'/times/5min_cron.php')) {
include($realPath.'/times/5min_cron.php');
}
if ($cron_5min['time'] <= ($timestamp-60)) {
$write = write_cron($timestamp, '5min_cron', 'cron_5min');
if ($write) {
$db->Query("INSERT INTO `m_z_analytics_empty` (`coins`, `1_min`, `1_day`, `date_added`) VALUES ('0.00', '1', '0', '".$date."')");
}
}
5分钟cron.php
<? $cron_5min['time'] = '1514768460'; ?>
1条答案
按热度按时间nbnkbykc1#
改变
进入