MySQL Delete Records Older Than X Minutes?

前端 未结 5 483
攒了一身酷
攒了一身酷 2020-12-30 08:18

I\'ve searched quite a bit and found a few solutions that did not end up working for me and can\'t understand why.

I have a table with a timestamp column. The MySQL

5条回答
  •  情歌与酒
    2020-12-30 08:41

    PHP Code :

    //Your Database Details
    
    $conn = mysqli_connect("localhost","root","","tifu");
    
    //Actual Core thing
    
    $delete_otp = mysqli_query($conn,"DELETE FROM temp_project_member_details WHERE create_at < ('" . date("Y-m-d H:i:s"). "' - INTERVAL 10 MINUTE)"); 
    

    Note : Here temp_project_member_details : Table Name in the database tifu

    and create_at : Field name inside the Table temp_project_member_details which has Date and Time stored using the same function '" . date("Y-m-d H:i:s"). "'

    Screenshot of Deleting After 10 minute code

    Screenshot of the storage of Date and Time in the create_at field of table as described in answer

提交回复
热议问题