简体   繁体   中英

How can I update my table after X minutes?

How I can update my table after X minute from my action

I send this request:

$req = Query("UPDATE clients SET lockclient = 0 WHERE id = $id")

And I want create the event after 5 min.

UPDATE clients SET lockclient = 1 WHERE id = $id

I tried to create the event with stored procedure , but this is imposible

DELIMITER $$ 

CREATE PROCEDURE proc
   (  
      idClient INTEGER 
   ) 
   BEGIN 
        CREATE EVENT updateClientLock
            ON SCHEDULE
                AT NOW() + INTERVAL 5 MINUTE
            ON COMPLETION NOT PRESERVE
            ENABLE
        DO BEGIN
            UPDATE client set lockclient = 0 where id = idClient ;
        END

   END$$ 

DELIMITER ;

Is there another way to do this?

通过使用X分钟的cron作业文件,您可以执行此操作,它将在您指定的时间后自动调用它

The solution of the problem :

static public function eventUpdateLockClient($id, $min)
{
    $bdd = new mysqli ($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    $sql1 = "CREATE EVENT updateClientLock$id
        ON SCHEDULE
        AT NOW() + INTERVAL $min MINUTE
        ON COMPLETION NOT PRESERVE
        ENABLE
        DO BEGIN
            UPDATE clients set lockclient = 0 where id = $id ;
        END";
    $bdd->query(${"sql1"});

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM