I'm looking for a way to automatically insert row to MySQL. Currently I using PHP Cron to do this, but values don't look perfect in MySQL - photo below.
What should I do to get clearly date_added values like for example:
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
I want to do this because it's important for me to make analytics and remove all empty data if exists. Below script is a 60 seconds cron made in php.
$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."')");
}
}
5min_cron.php
<? $cron_5min['time'] = '1514768460'; ?>