SELECT then immediately DELETE mysql record

后端 未结 5 2180
情深已故
情深已故 2021-01-17 14:14

I have a PHP script that runs a SELECT query then immediately deletes the record. There are multiple machines that are pinging the same php file and fetching data from the s

5条回答
  •  梦谈多话
    2021-01-17 14:51

    Put your delete queries inside the while loop, just incase you ever want to increase the limit from your select.

    
    

    The above code would be just the same as running:

    mysql_query("DELETE FROM `queue` LIMIT 1") or die(mysql_error());
    

    Be careful using your delete query, if the email field is blank, it will delete all rows that have a blank email. Add LIMIT 1 to your delete query to avoid multiple rows being deleted.

    To add a random delay, you could add a sleep to the top of the script,

    eg:

    
    

提交回复
热议问题