In the provided PHP code snippet, what improvements or best practices could be implemented to enhance its functionality or efficiency?

The provided PHP code snippet lacks error handling for the database connection, which can lead to potential issues if the connection fails. To enhance its functionality and efficiency, it is recommended to implement error handling using try-catch blocks to gracefully handle any potential errors that may occur during the database connection process.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>