What are the advantages and disadvantages of using text files versus a MySQL database for storing guestbook entries in PHP?

When deciding between using text files or a MySQL database for storing guestbook entries in PHP, some advantages of using text files include simplicity, ease of implementation, and portability. On the other hand, advantages of using a MySQL database include better organization of data, scalability, and the ability to easily query and retrieve specific information. However, using text files may not be as efficient for large amounts of data or complex queries compared to a database.

// Example of using a MySQL database to store guestbook entries in PHP

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "guestbook";

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

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

// Insert guestbook entry into database
$name = $_POST['name'];
$message = $_POST['message'];

$sql = "INSERT INTO entries (name, message) VALUES ('$name', '$message')";

if ($conn->query($sql) === TRUE) {
    echo "New entry added successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

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