Created
February 22, 2014 17:58
-
-
Save chadothompson/9159018 to your computer and use it in GitHub Desktop.
Making an Oracle RAC connection with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
## USERNAME / PASSWORD FOR ORACLE DATABASE | |
$USERID = 'USER'; | |
$PASSWORD = 'PASSWORD'; | |
## RAC CONNECTION STRING | |
$RAC_CONN_STR = "(DESCRIPTION = | |
(ADDRESS = (PROTOCOL = TCP)(HOST = first.database.host)(PORT = 1521)) | |
(ADDRESS = (PROTOCOL = TCP)(HOST = second.database.host)(PORT = 1521)) | |
(LOAD_BALANCE = yes) | |
(CONNECT_DATA = | |
(SERVER = DEDICATED) | |
(SERVICE_NAME = dbsvc) | |
(FAILOVER_MODE = | |
(TYPE = SELECT) | |
(METHOD = BASIC) | |
(RETRIES = 180) | |
(DELAY = 5) | |
) | |
) | |
)"; | |
## MAKE A CONNECTION TO THE ORACLE DB | |
$conn = oci_pconnect($USERID, $PASSWORD, $RAC_CONN_STR); | |
$stid = oci_parse($conn, "SELECT 'Connection Successful' AS result FROM DUAL"); | |
oci_execute($stid); | |
echo "<table border='1'>\n"; | |
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { | |
echo "<tr>\n"; | |
foreach ($row as $item) { | |
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n"; | |
} | |
echo "</tr>\n"; | |
} | |
echo "</table>\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment