How can auto-increment IDs be used to manage and delete older entries in a PHP application?
Auto-increment IDs can be used to manage and delete older entries in a PHP application by setting a threshold value for the ID. Entries with IDs below this threshold can be considered older and can be deleted from the database to manage the data size.
// Set the threshold value for the ID
$threshold_id = 1000;
// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');
// Delete entries with IDs below the threshold
$stmt = $pdo->prepare('DELETE FROM table_name WHERE id < :threshold_id');
$stmt->bindParam(':threshold_id', $threshold_id, PDO::PARAM_INT);
$stmt->execute();