How can the code snippet provided be modified to display a custom message like "Not found" when a database record is not present?

To display a custom message like "Not found" when a database record is not present, we can modify the code to check if the query returns any rows and display the custom message if no rows are found. We can use the `rowCount()` function to check the number of rows returned by the query and then display the custom message accordingly.

<?php
// Execute the query
$stmt = $pdo->prepare("SELECT * FROM table WHERE id = :id");
$stmt->execute(['id' => $id]);

// Check if any rows are returned
if ($stmt->rowCount() > 0) {
    // Display the results
    while ($row = $stmt->fetch()) {
        // Display the record
    }
} else {
    // Display custom message
    echo "Not found";
}
?>