What are the best practices for handling database connections in PHP when using Access?

When working with Access databases in PHP, it is important to properly handle database connections to ensure efficient and secure operations. One recommended best practice is to use a PDO (PHP Data Objects) connection with Access to prevent SQL injection attacks and provide a more flexible and secure way to interact with the database.

try {
    $conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=path/to/your/access/database.accdb");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}