That doesn't change anything so it's the same.
- You can set cron where it's will be delete every setted time. ( full simple example below)
- Or you can set schedule for it ( full example below )
- Or you can play manually like this ( below example with how many )
Here is cron where its will be deleting every 1 hour php file delete_topics.php , so what's left to do is just add database info in to this and set up cron properly ( to set up cron you can via your hosting provider ( if the provider is not old you can do via dashboard easy.. ) but if the hosting provider do not have this function then you need to make manually
<?php
function deleteOldTopics() {
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "DELETE FROM forums_topics WHERE start_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 2 YEAR)) LIMIT 100";
$stmt = $conn->prepare($sql);
$stmt->execute();
echo "[Success]";
} catch(PDOException $e) {
echo "[ERROR] : " . $e->getMessage();
}
$conn = null;
}
deleteOldTopics();
?>
Here is example of deleting 100 topics in phpmyadmin:
DELETE FROM forums_topics
WHERE start_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 2 YEAR))
LIMIT 100;
Here is simple (in phpmyadmin) example of setting up schedule for deleting posts here every 1 hour will be deleting 100 topics ( or how many you want if needed change it ) and you can keep it forever )
I personally have similar schedule for my large databases where I delete over 20k rows every 7 minutes and it works perfectly without any crashes or something like that.
CREATE EVENT delete_old_topics
ON SCHEDULE EVERY 1 HOUR
DO
BEGIN
DECLARE rows_affected INT;
START TRANSACTION;
DELETE FROM forums_topics
WHERE start_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 2 YEAR))
LIMIT 100;
SELECT ROW_COUNT() INTO rows_affected;
COMMIT;
IF rows_affected > 0 THEN
SELECT CONCAT(rows_affected, ' topics deleted.') AS Message;
ELSE
SELECT 'No topics deleted.' AS Message;
END IF;
END;