What are the best practices for handling database IDs versus names in PHP URLs to ensure long-term link stability and user readability?

When handling database IDs versus names in PHP URLs, it's best to use a combination of both for long-term link stability and user readability. This can be achieved by including a unique identifier (ID) in the URL along with a slug or name that is more user-friendly. This way, the ID ensures a direct and unambiguous reference to the database record, while the name enhances readability for users.

// Example of generating a URL with both ID and name
$id = 123; // Database ID
$name = "example-name"; // Name or slug
$url = "https://example.com/page.php?id={$id}&name={$name}";

// Example of retrieving data based on ID and name from URL
$id = $_GET['id']; // Retrieve ID from URL
$name = $_GET['name']; // Retrieve name from URL

// Use $id and $name to fetch data from the database