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

Using a MySQL database for storing guestbook entries in PHP allows for efficient data storage, retrieval, and management. It also provides scalability and flexibility for future enhancements. However, setting up and maintaining a MySQL database requires additional resources and technical expertise compared to using flat files or other simpler storage methods.

// 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);
}