Search code examples
phpcommandexecute

How can I insert a delay sql statement using PHP?


I would like to provide a web site for user, when the user input somethings, I will put it into the DB. But the command won't execute when the user access the .php. I would like to execute after a while.... This is something like this...

10:00 am
User makes the request, and saying that the record will write in the DB one hour later. 

11:00 am 
The request execute, and the DB write a new record. 

How Can I do so? also, I would like to add an ability for user to cancel the request.....Something like this:

10:00 am
User makes the request, and saying that the record will write in the DB one hour later. 

10:30 am
User cancels the request.

11:00 am 
Nothing won't execute.

Any ideas on that? Thank you.


Solution

    • When user input, save that input in database table but set a column(verified) value '0'
    • After one hour a cron job will set column(verified) value as '1'
    • If user cancel before verification, delete that record

    Example:

    table user_input:

    user_id | input |    input_time     | verified
       1    |  500  | 2011-01-01 12:20  |    1
       2    |  700  | 2011-01-01 01:20  |    0
    

    OR

    • create a new table to store input requests
    • After one hour a cron job will transer all request to original table.
    • If user cancel before one hour, delete that record from requests table.

    Example:

    table user_input:

    user_id | input
       1    |  500 
       2    |  700 
    

    table user_requests:

    user_id  |  input  |    input_time
       3     |   200   | 2011-01-01 07:20