php - MySql Insert Query based on Timestamp (delayed insert)

713

i need to dodelayedmysql insert into my database based on the time choosen.

Example:Timestamp choosen ="2013-04-03 10:12:00"

so i want myinsert query to get executed at this("2013-04-03 10:12:00") particular time.

$qry = mysql_query("INSERT INTO table (field) value ($value)");

i am having amysql innoDB database.

and i will be accepting thistimestamp value from user from aHTML+PHP interface.

and yes, idont want to docron jobs

883

Answer

Solution:

No option without cron job...

You need acron job setup forevery minute, in which the query is looking for any matching timestamp for the insert query.

But for every minutecron job is not better for DB health if you have more and more data to insert, you should think again about the time interval for better performance.

555

Answer

Solution:

You could insert data into additional table, then use MySQL events to copy records into target table at exact time. For example -

CREATE EVENT event1
  ON SCHEDULE AT '2013-04-03 20:00:00'
  DO 
BEGIN
  INSERT INTO <table> SELECT * FROM <temp table>;
  TRUNCATE TABLE <temp table>;
END

Using the Event Scheduler.

People are also looking for solutions to the problem: php - Selecting latest version of a class

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.