What are the advantages and disadvantages of using a file-based database for a guestbook in PHP?

Using a file-based database for a guestbook in PHP can be advantageous because it is simple to implement, does not require a separate database server, and is easy to backup and transfer. However, it may not be as efficient for handling large amounts of data, lacks advanced querying capabilities, and could potentially lead to data corruption if not properly managed.

// Code snippet for implementing a file-based database for a guestbook in PHP

// Define the file path for storing guestbook entries
$guestbookFile = 'guestbook.txt';

// Function to add a new entry to the guestbook
function addGuestbookEntry($name, $message) {
    global $guestbookFile;
    
    $entry = $name . ': ' . $message . "\n";
    file_put_contents($guestbookFile, $entry, FILE_APPEND);
}

// Function to retrieve all entries from the guestbook
function getGuestbookEntries() {
    global $guestbookFile;
    
    $entries = file($guestbookFile, FILE_IGNORE_NEW_LINES);
    return $entries;
}