In the context of the provided code, what are the benefits of using mysqli or PDO instead of the deprecated mysql functions for database interactions in PHP?

The deprecated mysql functions in PHP are no longer recommended for database interactions due to security vulnerabilities and lack of support. It is recommended to use either mysqli (MySQL Improved) or PDO (PHP Data Objects) for safer and more secure database operations in PHP.

// Using mysqli for database interactions
$mysqli = new mysqli("localhost", "username", "password", "database_name");

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

// Perform query
$result = $mysqli->query("SELECT * FROM table_name");

// Fetch data
while ($row = $result->fetch_assoc()) {
    // Process data
}

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