Are there any best practices to follow when connecting PHP to Oracle DB?

When connecting PHP to an Oracle database, it is recommended to use the PDO (PHP Data Objects) extension for a more secure and efficient connection. Additionally, it is important to properly handle errors and exceptions during the connection process to ensure smooth functionality.

<?php
// Oracle database connection settings
$tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))";
$username = "username";
$password = "password";

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