Reputation: 141
How to insert values into database table every two minutes?
I have code that doing every second that will explode my mysql database, which I do not want it happen. So I want to set it to 2 min.
$query="INSERT INTO $tablename VALUES ($temp,now())";
Here is the code for every second sent it to my databse.
and the code below is to set it two min , but is doesn't work
$timestamp=DATE_SUB(now(), INTERVAL 2 MINUTE);
$query="INSERT INTO $tablename VALUES ($temp,$timestamp)";
Some help me . thanks
Upvotes: 0
Views: 1899
Reputation: 2668
Apart from completely wrong approach (you need cron daemon to control tasks running every n minutes) , possibly what you're trying to do is to use mysql's date_sub()
$mysqlString= 'DATE_SUB(now(), INTERVAL 2 MINUTE)'; //this makes it a string
$query="INSERT INTO $tablename VALUES ($temp, {$mysqlString})";
echo $query;
Upvotes: 0
Reputation: 2002
Maybe my answer will not satisfy you but it's a mistake to make a task every 2 minute with a web framework. When you close your web browser, the task will not continue. This kind of daemon task must be done with CRONTAB.
Upvotes: 2