In the context of a guestbook project, what are the advantages and disadvantages of storing data in a database versus in individual files?

Storing data in a database offers advantages such as easier data manipulation, scalability, and better data organization. However, it may require more resources and expertise to set up and maintain. Storing data in individual files may be simpler and more straightforward, but it can become cumbersome to manage as the amount of data grows.

// Example of storing data in a database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "guestbook";

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

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

// Insert data into database
$sql = "INSERT INTO entries (name, message) VALUES ('John Doe', 'Hello world')";
if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

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