How can you reset an auto-incremented ID in a MySQL database table back to 0?

If you want to reset an auto-incremented ID in a MySQL database table back to 0, you can achieve this by altering the table's auto-increment value using a SQL query. This can be done by setting the auto-increment value to 1 and then truncating the table to remove all existing records. However, keep in mind that this operation will permanently delete all data in the table.

<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Reset auto-increment value to 1
$sql = "ALTER TABLE table_name AUTO_INCREMENT = 1";
$conn->query($sql);

// Truncate table to remove all existing records
$sql = "TRUNCATE TABLE table_name";
$conn->query($sql);

// Close connection
$conn->close();
?>